AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.6k stars 650 forks source link

Loop and variable bug #2825

Closed lortonx closed 3 months ago

lortonx commented 4 months ago

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

CountBleck commented 4 months ago

That does seem to be the case...

CountBleck commented 4 months ago

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.