another bugfix for block bindings
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 29 Dec 2020 21:12:33 +0000 (15:12 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 29 Dec 2020 21:12:33 +0000 (15:12 -0600)
onyx
progs/poly_solidify.onyx
src/onyxparser.c

diff --git a/onyx b/onyx
index 3764f3bab67cc5780cb5414e576d6b530ee08866..217ea22c9838e25bdcd2712d5c3df742d11c5f87 100755 (executable)
Binary files a/onyx and b/onyx differ
index 3e067055356c4b7856c0f879e32022e08994afb5..e197154aca191fd5b014dc88b1ae40bfff208f33 100644 (file)
@@ -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) {
index 37479335c56be08f76bc8247ee90897cd4e4fd90..1a5d6b1a00882e168c8cc2a9bea53d2afc7170e5 100644 (file)
@@ -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