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

When declaring an @(rodata, static) slice literal the fixed array backing is still mutable (compiles) but does not crash (which is desired) #4801

Open
speechfreedoms opened this issue Feb 6, 2025 · 1 comment

Comments

@speechfreedoms
Copy link

speechfreedoms commented Feb 6, 2025

minimal example

package test
import "core:fmt"
main :: proc() {
    @(rodata, static)
    data := [][]f64{{1, 2, 3, 4}, {5, 6, 7, 8, 9, 10}}
    fmt.println(data[0][0]) // 1
    data[0][0] = 42 // will compile, but NOT crash at runtime
    fmt.println(data[0][0]) // 42
}

Issue: when declaring an @(rodata, static) slice literal the fixed array backing is still considered mutable by the compiler but does NOT crash at runtime

Desired

Compiler should error (if possible) when trying to mutate a slice literal but should at least crash at runtime if compiler passes it

compiler command

odin run . or odin build .

system info

Odin 2025-01
Windows
LLVM 18.1.8

suggested labels

?

@jasonKercher
Copy link
Contributor

I think he uploaded the wrong example. The one he uploaded works as expected. This does not:

package test
import "core:fmt"
main :: proc() {
    @(rodata, static)
    data := [][]f64{{1, 2, 3, 4}, {5, 6, 7, 8, 9, 10}}
    fmt.println(data[0][0]) // 1
    data[0][0] = 42
    fmt.println(data[0][0]) // 42
}

@speechfreedoms speechfreedoms changed the title When declaring an @(rodata) slice literal the fixed array backing is still mutable When declaring an @(rodata, static) slice literal the fixed array backing is still mutable (compiles) but does not crash Feb 6, 2025
@speechfreedoms speechfreedoms changed the title When declaring an @(rodata, static) slice literal the fixed array backing is still mutable (compiles) but does not crash When declaring an @(rodata, static) slice literal the fixed array backing is still mutable (compiles) but does not crash (which is desired) Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants