From fdc9b6a3841d7346dab6f4aeea06322be0d3ee95 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 14 Nov 2022 22:10:12 +0100 Subject: compiler: fix `??=`, `||=` and `&&=` logical assignment semantics When compiling logical assignment expressions, ensure that the right hand side of the assignment is not evaluated when the assignment condition is unfulfilled. Signed-off-by: Jo-Philipp Wich --- tests/custom/00_syntax/25_and_or_assignment | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/custom/00_syntax') diff --git a/tests/custom/00_syntax/25_and_or_assignment b/tests/custom/00_syntax/25_and_or_assignment index 4dbc5f3..d6a9415 100644 --- a/tests/custom/00_syntax/25_and_or_assignment +++ b/tests/custom/00_syntax/25_and_or_assignment @@ -53,3 +53,33 @@ expression result if the lhs is falsy. printf("%.J\n", [ x, y, z ]); %} -- End -- + + +3. Ensure that the assignment value expression is not evaluated if the +assignment condition is false. + +-- Expect stdout -- +[ + 0, + 0, + 0 +] +-- End -- + +-- Testcase -- +{% + a = 0; + b = 0; + c = 0; + + x = false; + y = false; + z = true; + + x ??= a++; + y &&= b++; + z ||= c++; + + printf("%.J\n", [ a, b, c ]); +%} +-- End -- -- cgit v1.2.3