compile: Make sure the matcher is not overridden in nested assignments

This commit is contained in:
Laria 2022-08-04 21:38:13 +02:00
parent d731fa828a
commit 19a5191e59

View file

@ -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);