Skip to content

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

Description

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

?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions