diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 00:13:53 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-12 00:13:53 -0400 |
| commit | fa7e52787f81f3673f9d57e9e4ba7fc015ca8432 (patch) | |
| tree | f184ad44625d04d1bf80af8e83f4512124b3ff2f /typecheck.c | |
| parent | 8e300312a077421477fdeb6453f625461799ffc0 (diff) | |
Add postfix `!` operator for optionals
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 7 |
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; |
