From: Brendan Hansen Date: Tue, 27 Sep 2022 22:24:58 +0000 (-0500) Subject: bugfix with nested #inject blocks X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6c5452636a659f73d6f8359d224d8a6d7f11b717;p=onyx.git bugfix with nested #inject blocks --- diff --git a/compiler/src/parser.c b/compiler/src/parser.c index 1ea389f0..6e6f3b0e 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -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;