aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-11 23:17:03 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-11 23:17:03 -0400
commitc034175ae1cbe53bc0e7e1ae71b51c64dcc3402a (patch)
tree8a6b1754c7530399a563d7b80a669d6d08d8af37 /typecheck.c
parentcfef667a899339a0fd5b79214d581db6ede10748 (diff)
Add optional:or_else(fallback) and optional:or_fail(message)
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c
index e500dfa7..9ad151a3 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -838,6 +838,12 @@ type_t *get_type(env_t *env, ast_t *ast)
else if (streq(call->name, "sorted")) return self_value_t;
code_err(ast, "There is no '%s' method for %T tables", call->name, self_value_t);
}
+ case OptionalType: {
+ type_t *nonnull = Match(self_value_t, OptionalType)->type;
+ if (streq(call->name, "or_else")) return nonnull;
+ else if (streq(call->name, "or_fail")) return nonnull;
+ code_err(ast, "There is no '%s' method for optional %T values", call->name, nonnull);
+ }
default: {
type_t *fn_type_t = get_method_type(env, call->self, call->name);
if (!fn_type_t)