From 6c5452636a659f73d6f8359d224d8a6d7f11b717 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 27 Sep 2022 17:24:58 -0500 Subject: [PATCH] bugfix with nested #inject blocks --- compiler/src/parser.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; -- 2.25.1