bugfix with nested #inject blocks
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 27 Sep 2022 22:24:58 +0000 (17:24 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 27 Sep 2022 22:24:58 +0000 (17:24 -0500)
compiler/src/parser.c

index 1ea389f04240872c4a729b1d9d4063bbcb824e99..6e6f3b0e7cd8ba8c5bbce309b1bf7b2ac0a8738c 100644 (file)
@@ -3278,7 +3278,11 @@ static void parse_top_level_statement(OnyxParser* parser) {
                 parser->parse_calls = 1;
 
                 if (peek_token(0)->type == '{') {
-                    assert(!parser->injection_point);
+                    if (parser->injection_point) {
+                        onyx_report_error(dir_token->pos, Error_Critical, "#inject blocks cannot be nested.");
+                        return;
+                    }
+
                     parser->injection_point = injection_point;
 
                     expect_token(parser, '{');
@@ -3387,6 +3391,11 @@ submit_binding_to_entities:
     {
         if (!binding) return;
 
+        //
+        // If this binding is inside an #inject block,
+        // swap the binding node for an injection node
+        // onto the injection point. This is the easiest
+        // way I could think of doing this.
         if (parser->injection_point) {
             AstInjection *injection = make_node(AstInjection, Ast_Kind_Injection);
             injection->token = parser->injection_point->token;