-
Notifications
You must be signed in to change notification settings - Fork 443
Open
Description
Summary
When a loop variable is shadowed inside a for loop and then captured by an immediately-invoked function literal, the Gno VM panics with:
unexpected NameExpr type for GetPointerToMaybeHeapDefine
This does not happen in Go, where the program compiles and runs fine.
Reproduction
package main
import "fmt"
func main() {
for i := 0; i < 3; i++ {
i := i // shadow loop variable
func() {
i += 1
}()
}
fmt.Println("Hello, 世界")
}Running this in Gno produces:
unexpected panic: unexpected NameExpr type for GetPointerToMaybeHeapDefine
stacktrace:
main<VPBlock(1,0)>()
main/for25.gno:7
...
panic: unexpected NameExpr type for GetPointerToMaybeHeapDefine
Expected Behavior
- The inner
i := ishadows the outer loop variable. - The closure mutates the shadowed variable.
- No runtime or compile error.
ltzmaxwellltzmaxwell
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Triage