From 385419f95c6b9c35a7c2a6168f82f7aa4a44e22b Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sat, 18 Jul 2026 13:18:45 -0700 Subject: fix scoping big --- parser.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index 40cdb1c..4779e73 100644 --- a/parser.c +++ b/parser.c @@ -324,6 +324,9 @@ static void parse_group(struct group_node* p_node) { static void parse_if(struct if_node* p_node) { expect_kw("if"); + scope_push(&scope); + p_node->scope = scope; + expect(TK_LPAREN); p_node->cond = protected_alloc(sizeof(struct expr_node)); parse_expr(p_node->cond); @@ -333,11 +336,14 @@ static void parse_if(struct if_node* p_node) { parse_stmt(p_node->true_branch); peek_or_panic(); - if (tok.type != TK_IDENT || strcmp(tok.data.ident, "else") != 0) return; - expect_kw("else"); + if (tok.type == TK_IDENT && strcmp(tok.data.ident, "else") == 0) { + expect_kw("else"); - p_node->false_branch = protected_alloc(sizeof(struct stmt_node)); - parse_stmt(p_node->false_branch); + p_node->false_branch = protected_alloc(sizeof(struct stmt_node)); + parse_stmt(p_node->false_branch); + } + + scope_pop(&scope); } static void parse_stmt_assign(struct stmt_node* p_node) { @@ -419,6 +425,9 @@ static void parse_args_decl(struct args_decl_node** pp_decl) { } static void parse_fn_decl(struct fn_decl_node* p_node) { + if (scope->next_out != NULL) + PARSER_PANIC("functions can only be define in the root scope"); + parse_type_ref(&p_node->return_type); expect(TK_IDENT); -- cgit v1.2.3