diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-18 15:27:07 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-18 15:27:07 -0400 |
| commit | 7c0a77df332651c4dd6d4a6c80d3d7afabb22527 (patch) | |
| tree | 4c1b883228263bfa38565926495d99e192877821 | |
| parent | d94c1057accb197ec3b957fb91ff75597ac54c40 (diff) | |
Handle function type annotations without returns better
| -rw-r--r-- | parse.c | 3 | ||||
| -rw-r--r-- | typecheck.c | 2 |
2 files changed, 2 insertions, 3 deletions
@@ -479,8 +479,7 @@ type_ast_t *parse_func_type(parse_ctx_t *ctx, const char *pos) { arg_ast_t *args = parse_args(ctx, &pos, true); expect_closing(ctx, &pos, ")", "I wasn't able to parse the rest of this function type"); spaces(&pos); - if (!match(&pos, "->")) return NULL; - type_ast_t *ret = optional(ctx, &pos, parse_type); + type_ast_t *ret = match(&pos, "->") ? optional(ctx, &pos, parse_type) : NULL; return NewTypeAST(ctx->file, start, pos, FunctionTypeAST, .args=args, .ret=ret); } diff --git a/typecheck.c b/typecheck.c index 4a73b32d..a48fa8ee 100644 --- a/typecheck.c +++ b/typecheck.c @@ -53,7 +53,7 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) } case FunctionTypeAST: { auto fn = Match(ast, FunctionTypeAST); - type_t *ret_t = parse_type_ast(env, fn->ret); + type_t *ret_t = fn->ret ? parse_type_ast(env, fn->ret) : Type(VoidType); if (has_stack_memory(ret_t)) code_err(fn->ret, "Functions are not allowed to return stack references, because the reference may no longer exist on the stack."); arg_t *type_args = NULL; |
