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

Loop and variable bug #2825

Closed
lortonx opened this issue Mar 10, 2024 · 2 comments · Fixed by #2826
Closed

Loop and variable bug #2825

lortonx opened this issue Mar 10, 2024 · 2 comments · Fixed by #2826
Labels

Comments

@lortonx
Copy link

lortonx commented Mar 10, 2024

Bug description

The compiler considers "i" to be one variable, not two, and an infinite loop occurs.

Steps to reproduce

run

    for(let i = 0; i < 30; i++) {
        let i = 10
        while(i--) {}
    }

AssemblyScript version

0.27.15

@lortonx lortonx added the bug label Mar 10, 2024
@CountBleck
Copy link
Member

That does seem to be the case...

@CountBleck
Copy link
Member

CountBleck commented Mar 10, 2024

Actually, a separate local variable is created, but it shadows the first one. See here. Lines 36-39 would be the i++, which is writing to local 1 instead of local 0.

CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Mar 10, 2024
It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, code like this should no longer compile:

for (let i = 0; i < 2; j++) { let j = 0; }

Fixes AssemblyScript#2825.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Mar 10, 2024
It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, incrementors no longer have access to such variables.

Fixes AssemblyScript#2825.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Mar 10, 2024
It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, incrementors no longer have access to such variables.

Fixes AssemblyScript#2825.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Mar 12, 2024
It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, incrementors no longer have access to such variables.

Fixes AssemblyScript#2825.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Mar 12, 2024
It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, incrementors no longer have access to such variables.

Fixes AssemblyScript#2825.
CountBleck added a commit that referenced this issue Apr 2, 2024
It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, incrementors no longer have access to such variables.

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

Successfully merging a pull request may close this issue.

2 participants