From 19a5191e5966ecda43a07c24745182eda3af309e Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Thu, 4 Aug 2022 21:38:13 +0200 Subject: [PATCH] compile: Make sure the matcher is not overridden in nested assignments --- src/compile.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compile.c b/src/compile.c index 5253e35..68eefd7 100644 --- a/src/compile.c +++ b/src/compile.c @@ -533,6 +533,18 @@ compile_complex_assignment( struct apfl_position position, struct instruction_list *ilist ) { + // TODO: This is not entirely correct: By evaluating the RHS first, it might + // affect variables used in the matcher. This is only really important when + // predicates are used, which are not yet implemented: + // + // x = {true} + // foo?x = ({x={false}}) + // + // This should succeed: The predicate x should be loaded before the + // evaluation of the rhs occurs. With our current implementation it will + // fail, though. + TRY(compile_expr(compiler, assignment->rhs, ilist)); + TRY(ilist_ensure_cap(compiler, ilist, 2)); struct matcher_instruction_list *milist; @@ -555,8 +567,6 @@ compile_complex_assignment( TRY(concat_ilists(compiler, ilist, ilists.newvars)); - TRY(compile_expr(compiler, assignment->rhs, ilist)); - TRY(ilist_ensure_cap(compiler, ilist, 1)); ilist_put_insn(ilist, INSN_MATCHER_MUST_MATCH);