aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-12 00:55:43 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-12 00:55:43 -0400
commit327d466b9543aee3983277ca4158e5b7aa06fdf8 (patch)
tree64028cc0ca38b76461a85be02e3103db600f0bcc /typecheck.c
parentfa7e52787f81f3673f9d57e9e4ba7fc015ca8432 (diff)
Table:get() now uses optional values instead of default or failure modes
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/typecheck.c b/typecheck.c
index b70db784..192a335b 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -832,14 +832,8 @@ type_t *get_type(env_t *env, ast_t *ast)
auto table = Match(self_value_t, TableType);
if (streq(call->name, "bump")) return Type(VoidType);
else if (streq(call->name, "clear")) return Type(VoidType);
- else if (streq(call->name, "get")) return table->value_type;
- else if (streq(call->name, "get_or_null")) {
- if (table->value_type->tag != PointerType)
- code_err(ast, "The table method :get_or_null() is only supported for tables whose value type is a pointer, not %T",
- table->value_type);
- auto ptr = Match(table->value_type, PointerType);
- return Type(OptionalType, .type=Type(PointerType, .pointed=ptr->pointed, .is_stack=ptr->is_stack, .is_readonly=ptr->is_readonly));
- } else if (streq(call->name, "has")) return Type(BoolType);
+ else if (streq(call->name, "get")) return Type(OptionalType, .type=table->value_type);
+ else if (streq(call->name, "has")) return Type(BoolType);
else if (streq(call->name, "remove")) return Type(VoidType);
else if (streq(call->name, "set")) return Type(VoidType);
else if (streq(call->name, "sorted")) return self_value_t;