Skip to content

unhelpful error message on comptime store to @constCasted pointer to comptime const #24157

Open
@mlugg

Description

@mlugg

Zig Version

0.15.0-dev.767+201c0f54a

Steps to Reproduce and Observed Output

//! repro.zig
comptime {
    const x: u32 = 42;
    const ptr: *u32 = @constCast(&x);
    ptr.* = 10;
}
$ zig build-obj repro.zig
repro.zig:5:11: error: unable to evaluate comptime expression
    ptr.* = 10;
    ~~~~~~^~~~
repro.zig:5:8: note: operation is runtime due to this operand
    ptr.* = 10;
    ~~~^~
repro.zig:2:1: note: 'comptime' keyword forces comptime evaluation
comptime {
^~~~~~~~

Expected Output

Something like this:

repro.zig:5:11: error: cannot store to constant memory
    ptr.* = 10;
    ~~~~~~^~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions