diff options
author | Bad Diode <bd@badd10de.dev> | 2022-04-19 10:55:40 -0300 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-04-19 10:55:40 -0300 |
commit | d9538a32bfe8e2cb9de4cdcfdf8a8c6e1a27ac3c (patch) | |
tree | 28e5f760f72b838bd2408351c0b525ab20a049e1 | |
parent | c69929cc501203829082b810bafe75a22947e00c (diff) | |
download | bdl-d9538a32bfe8e2cb9de4cdcfdf8a8c6e1a27ac3c.tar.gz bdl-d9538a32bfe8e2cb9de4cdcfdf8a8c6e1a27ac3c.zip |
Fix semantic analysis bug in block scoped functions
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/semantic.c | 4 |
2 files changed, 4 insertions, 1 deletions
@@ -52,6 +52,7 @@ process_source(const StringView *source, const char *file_name) { | |||
52 | 52 | ||
53 | // Symbol table generation and type checking. | 53 | // Symbol table generation and type checking. |
54 | ParseTree *parse_tree = semantic_analysis(roots); | 54 | ParseTree *parse_tree = semantic_analysis(roots); |
55 | check_errors(file_name); | ||
55 | if (mode == PRINT_SEMANTIC) { | 56 | if (mode == PRINT_SEMANTIC) { |
56 | viz_ast(parse_tree->roots); | 57 | viz_ast(parse_tree->roots); |
57 | return; | 58 | 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) { | |||
311 | node->expr_type = type; | 311 | node->expr_type = type; |
312 | } break; | 312 | } break; |
313 | case NODE_FUN: { | 313 | case NODE_FUN: { |
314 | node->expr_type = &default_types[TYPE_VOID]; | ||
315 | |||
314 | // Fill up new scope with parameters | 316 | // Fill up new scope with parameters |
315 | scope = alloc_scope(scope); | 317 | scope = alloc_scope(scope); |
316 | array_push(ast->scopes, scope); | 318 | array_push(ast->scopes, scope); |
@@ -336,7 +338,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { | |||
336 | } | 338 | } |
337 | } | 339 | } |
338 | Node *last_expr = body->block.expr[array_size(body->block.expr) - 1]; | 340 | Node *last_expr = body->block.expr[array_size(body->block.expr) - 1]; |
339 | node->expr_type = last_expr->expr_type; | 341 | node->fun.body->expr_type = last_expr->expr_type; |
340 | } else { | 342 | } else { |
341 | if (!resolve_type(ast, scope, body)) { | 343 | if (!resolve_type(ast, scope, body)) { |
342 | return false; | 344 | return false; |