From d9538a32bfe8e2cb9de4cdcfdf8a8c6e1a27ac3c Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 19 Apr 2022 10:55:40 -0300 Subject: Fix semantic analysis bug in block scoped functions --- src/main.c | 1 + src/semantic.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index fc991d2..7878c57 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ process_source(const StringView *source, const char *file_name) { // Symbol table generation and type checking. ParseTree *parse_tree = semantic_analysis(roots); + check_errors(file_name); if (mode == PRINT_SEMANTIC) { viz_ast(parse_tree->roots); return; diff --git a/src/semantic.c b/src/semantic.c index 6c9f290..dd95d28 100644 --- a/src/semantic.c +++ b/src/semantic.c @@ -311,6 +311,8 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { node->expr_type = type; } break; case NODE_FUN: { + node->expr_type = &default_types[TYPE_VOID]; + // Fill up new scope with parameters scope = alloc_scope(scope); array_push(ast->scopes, scope); @@ -336,7 +338,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { } } Node *last_expr = body->block.expr[array_size(body->block.expr) - 1]; - node->expr_type = last_expr->expr_type; + node->fun.body->expr_type = last_expr->expr_type; } else { if (!resolve_type(ast, scope, body)) { return false; -- cgit v1.2.1