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

type switch can modify for loop's variable #4682

Open
peperronii opened this issue Jan 12, 2025 · 0 comments
Open

type switch can modify for loop's variable #4682

peperronii opened this issue Jan 12, 2025 · 0 comments

Comments

@peperronii
Copy link

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Odin:    dev-2024-12-nightly:cf53404
OS:      macOS Ventura 13.6.9 (build 22G830, kernel 22.6.0)
CPU:     Apple M1
RAM:     8192 MiB
Backend: LLVM 18.1.8

Expected Behavior

Type Switch does not modify the variable and the compiler throws an error

Current Behavior

Type switch can modify the variable

Steps to Reproduce

U :: union {
    int,
    bool,
}

ar := [3]U{1, 3, false}

for u in ar {
    switch &v in u {
        case int :
            v = 2  // this should've thrown an error as u should be immutable
            assert(u == 2)
         case bool : 
            v = true // this should too
            assert(u == true)
    }     
}

Failure Logs

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

No branches or pull requests

1 participant