From fa7e52787f81f3673f9d57e9e4ba7fc015ca8432 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 12 Sep 2024 00:13:53 -0400 Subject: Add postfix `!` operator for optionals --- typecheck.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'typecheck.c') 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; -- cgit v1.2.3