From: Brendan Hansen Date: Tue, 29 Dec 2020 21:12:33 +0000 (-0600) Subject: another bugfix for block bindings X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=34ec60897920442e23fdb47ceeaa29595eaf26e5;p=onyx.git another bugfix for block bindings --- diff --git a/onyx b/onyx index 3764f3ba..217ea22c 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index 3e067055..e197154a 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -49,21 +49,26 @@ main :: proc (args: [] cstr) { } array_map :: proc (arr: [..] $T, f: proc (T) -> T) { - test2(); - foo := #solidify math.max { T = T }; is := (#type InternalStruct(T)).{ foo = foo(6, 2) }; printf("%i\n", is.foo); for ^v: arr do *v = f(*v); - test2 :: proc () { - test(); - println("WORLD!!!!"); - } + { + test2(); + + test2 :: proc () { + test(); + + is : InternalStruct([] u32); + + println("WORLD!!!!"); + } - test :: proc () { - println("HELLO!!!"); + test :: proc () { + println("HELLO!!!"); + } } InternalStruct :: struct ($SOMETHING) { diff --git a/src/onyxparser.c b/src/onyxparser.c index 37479335..1a5d6b1a 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -115,10 +115,8 @@ static void add_node_to_process(OnyxParser* parser, AstNode* node) { Scope* scope = parser->file_scope; if (!bh_arr_is_empty(parser->block_stack)) { - Scope* binding_scope = parser->block_stack[bh_arr_length(parser->block_stack) - 1]->binding_scope; - - if (binding_scope != NULL) - scope = binding_scope; + scope = parser->block_stack[bh_arr_length(parser->block_stack) - 1]->binding_scope; + assert(scope != NULL); } bh_arr_push(parser->results.nodes_to_process, ((NodeToProcess) { @@ -1021,17 +1019,7 @@ static i32 parse_possible_symbol_declaration(OnyxParser* parser, AstNode** ret) if (parser->curr->type == ':') { AstBlock* current_block = parser->block_stack[bh_arr_length(parser->block_stack) - 1]; - if (current_block->binding_scope == NULL) { - // TODO: Check this is right. I suspect it may allow more things to be - // valid than I want it to. - - Scope* parent_scope = parser->file_scope; - if (bh_arr_length(parser->block_stack) > 1) { - parent_scope = parser->block_stack[bh_arr_length(parser->block_stack) - 2]->binding_scope; - } - - current_block->binding_scope = scope_create(parser->allocator, parent_scope, current_block->token->pos); - } + assert(current_block->binding_scope != NULL); AstBinding* binding = parse_top_level_binding(parser, symbol); symbol_introduce(current_block->binding_scope, symbol, binding->node); @@ -1341,6 +1329,13 @@ static AstBlock* parse_block(OnyxParser* parser) { AstBlock* block = make_node(AstBlock, Ast_Kind_Block); bh_arr_new(global_heap_allocator, block->allocate_exprs, 4); + { + Scope* parent_scope = parser->file_scope; + if (!bh_arr_is_empty(parser->block_stack)) + parent_scope = bh_arr_last(parser->block_stack)->binding_scope; + block->binding_scope = scope_create(parser->allocator, parent_scope, parser->curr->pos); + } + bh_arr_push(parser->block_stack, block); // NOTE: --- is for an empty block