aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-12 00:13:53 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-12 00:13:53 -0400
commitfa7e52787f81f3673f9d57e9e4ba7fc015ca8432 (patch)
treef184ad44625d04d1bf80af8e83f4512124b3ff2f /typecheck.c
parent8e300312a077421477fdeb6453f625461799ffc0 (diff)
Add postfix `!` operator for optionals
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c
index 9ad151a3..b70db784 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -567,6 +567,13 @@ type_t *get_type(env_t *env, ast_t *ast)
code_err(ast, "This value is already optional, it can't be converted to optional");
return Type(OptionalType, .type=t);
}
+ case NonOptional: {
+ ast_t *value = Match(ast, NonOptional)->value;
+ type_t *t = get_type(env, value);
+ if (t->tag != OptionalType)
+ code_err(value, "This value is not optional. Only optional values can use the '!' operator.");
+ return Match(t, OptionalType)->type;
+ }
case TextLiteral: return TEXT_TYPE;
case TextJoin: {
const char *lang = Match(ast, TextJoin)->lang;