Odin
Odin copied to clipboard
loop labels don't respect scope in switch statement
Context
Odin: dev-2024-10:8006ba919
OS: Manjaro Linux, Linux 6.1.106-1-MANJARO
CPU: 12th Gen Intel(R) Core(TM) i7-1260P
RAM: 31806 MiB
Backend: LLVM 14.0.6
Expected Behavior
This should work, since the outer labels are in different scopes:
ru := 'x'
switch ru {
case ' ', '\n':
outer: for i in 0 ..= 10 {
for j in 0 ..= 10 {
if i == j {
break outer
}
}
}
case:
outer: for i in 0 ..= 10 {
for j in 0 ..= 10 {
if i == j {
break outer
}
}
}
}
Similar to how this works, declaring an s variable in different scopes is fine:
main :: proc() {
ru := 'x'
switch ru {
case ' ', '\n':
s := "Hello"
case:
s := "Hello"
}
}
Current Behavior
/home/tadeo/Desktop/test/o2/i.odin(24:3) Error: Duplicate label with the name 'outer'
outer: for i in 0 ..= 10 {
^~~~^