Skip to content

@intFromPtr at comptime has misleading error message #22177

Open
@rohlem

Description

@rohlem

Zig Version

0.14.0-dev.2371+c013f45ad

Steps to Reproduce and Observed Output

Current reproduction:

comptime {
    const x: u8 = 0;
    _ = @intFromPtr(&x);
}

Current compile error output:

.zig:3:9: error: unable to evaluate comptime expression
    _ = @intFromPtr(&x);
        ^~~~~~~~~~~~~~~
.zig:3:21: note: operation is runtime due to this operand
    _ = @intFromPtr(&x);
                    ^~

The note is somewhat misleading, because nothing about this operand is runtime.
It seems to me like the error note logic was copied from some other operation without much thought.
What's actually happening is that @intFromPtr itself is currently restricted to runtime contexts.
(See #15080, the plan is to eventually implement workaround semantics for comptime.)

Expected Output

Something along the lines of:

.zig:3:9: error: unable to evaluate comptime expression
    _ = @intFromPtr(&x);
        ^~~~~~~~~~~~~~~
.zig:3:21: note: @intFromPtr is currently only available at runtime

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