Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cached operations propagate incorrectly in switch statements #144

Closed
JeanJPNM opened this issue Feb 16, 2023 · 0 comments · Fixed by #145
Closed

Cached operations propagate incorrectly in switch statements #144

JeanJPNM opened this issue Feb 16, 2023 · 0 comments · Fixed by #145
Labels
bug Something isn't working

Comments

@JeanJPNM
Copy link
Collaborator

JeanJPNM commented Feb 16, 2023

Cached operations propagate incorreclty across switch case bodies. In the following example, it is visible in the output that
the results from the operations in the first case are being reused in the second, even though they will never be executed.

const x = Math.rand(10);
const y = Math.rand(2) > 1 ? 1 : 2;
switch (y) {
  case 1:
    print`${x + y} > ${x - y}`;
    break;
  case 2:
    print`${x - y} < ${x + y}`;
    break;
}

printFlush();

Output:

op rand x:1:6 10
op rand &t0 2
jump 5 lessThanEq &t0 1
set y:2:6 1
jump 6 always
set y:2:6 2
jump 9 strictEqual y:2:6 1
jump 15 strictEqual y:2:6 2
jump 18 always
op add &t1 x:1:6 y:2:6
op sub &t2 x:1:6 y:2:6
print &t1
print " > "
print &t2
jump 18 always
print &t2
print " < "
print &t1
printflush message1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant