Description
Each is branch inside a when block shares the same scope. Declaring a variable in one is branch prevents declaring the same variable name in another branch, which is incorrect — each branch is mutually exclusive and should have its own scope, like if/otherwise blocks do.
Repro
do classify(x int) -> (label string) {
when x {
is 1 {
mut label string = "one"
return label
}
is 2 {
mut label string = "two"
return label
}
default {
mut label string = "other"
return label
}
}
}
do main() {
println(classify(1))
println(classify(2))
println(classify(99))
}
Expected: Compiles and prints one, two, other. Each is block has its own scope.
Actual:
error[E4003]: variable 'label' already declared in this scope (line 4)
--> test.ez:8:13
Where to look
ezc/src/typechecker/typechecker.c — the NODE_WHEN_STMT case. Each is branch body needs scope_create()/restore around it, same as if/otherwise branches already have. The default branch needs the same treatment.
Description
Each
isbranch inside awhenblock shares the same scope. Declaring a variable in oneisbranch prevents declaring the same variable name in another branch, which is incorrect — each branch is mutually exclusive and should have its own scope, likeif/otherwiseblocks do.Repro
Expected: Compiles and prints
one,two,other. Eachisblock has its own scope.Actual:
Where to look
ezc/src/typechecker/typechecker.c— theNODE_WHEN_STMTcase. Eachisbranch body needsscope_create()/restore around it, same asif/otherwisebranches already have. Thedefaultbranch needs the same treatment.