diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-21 13:00:53 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-21 13:00:53 -0500 |
| commit | f868d02b08688c04509d1abda5af89a182033d88 (patch) | |
| tree | af64c48127e0edfebb348edabbccbcc402d2070b /typecheck.c | |
| parent | 90573ba7a15bb47a11c1eb6f69ed04c01b69724d (diff) | |
Add `NULL` as a syntax for null values.
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c index b3d96d37..2d84c622 100644 --- a/typecheck.c +++ b/typecheck.c @@ -484,6 +484,8 @@ type_t *get_type(env_t *env, ast_t *ast) #pragma GCC diagnostic ignored "-Wswitch-default" switch (ast->tag) { case Null: { + if (!Match(ast, Null)->type) + return Type(OptionalType, .type=NULL); type_t *t = parse_type_ast(env, Match(ast, Null)->type); return Type(OptionalType, .type=t); } @@ -1061,6 +1063,9 @@ type_t *get_type(env_t *env, ast_t *ast) if (ret->tag == AbortType) ret = Type(VoidType); + if (ret->tag == OptionalType && !Match(ret, OptionalType)->type) + code_err(lambda->body, "This function doesn't return a specific optional type"); + if (lambda->ret_type) { type_t *declared = parse_type_ast(env, lambda->ret_type); if (can_promote(ret, declared)) |
