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

Reference error with loops such as for (var x = ..., y = x) #35

Open
Fuyukai opened this issue Apr 4, 2023 · 1 comment
Open

Reference error with loops such as for (var x = ..., y = x) #35

Fuyukai opened this issue Apr 4, 2023 · 1 comment

Comments

@Fuyukai
Copy link
Contributor

Fuyukai commented Apr 4, 2023

Stupid test code:

for (var x = 0, y = x; y < 10; y++) {
    console.log(y);
}

Gives off a ReferenceError: "x" is not defined..

Note that this works fine in regular Rhino:

$ rhino
Rhino 1.7.14
js> for (var x = 0, y = x; y < 10; y++) {
  > print(y);
  > };
0
1
2
3
4
5
6
7
8
9

Note that it works fine outside of a loop body:

var x = 1, y = x;
console.log(y);

Gives [23:42:03] [INFO ] server_scripts:test.js:2: 1.0.

@Fuyukai
Copy link
Contributor Author

Fuyukai commented Apr 5, 2023

My initial suspicious culprit is here, where the comment very helpfully explains what is going on: the loop body is being rewritten to move the variable assignment out of the loop body. This works for single assignments but results in a miscompilation for multiple assignments (I'm not sure why).

Just removing that seems to fix this but that seems obviously wrong so I'm going to keep digging as to why this causes the miscompilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant