zig icon indicating copy to clipboard operation
zig copied to clipboard

stage2 anyerror + @field() regression

Open billzez opened this issue 1 year ago • 1 comments

Zig Version

0.11.0-dev.63+8c4faa5f3

Steps to Reproduce and Observed Behavior

I used to be able to create error unions using @field:

const std = @import("std");

pub fn main() void {
    const e = @field(anyerror, "NotFound");
    std.debug.print("{}\n", .{@TypeOf(e)});
}

This was a handy way of creating error unions at compile time.

But now @TypeOf(e) is always anyerror

Expected Behavior

Stage1 evaluates TypeOf(e) to error{NotFound}

billzez avatar Nov 05 '22 06:11 billzez

I can use @Type for now, until its removed from the language.

    const E = @Type(std.builtin.Type{
        .ErrorSet = &[_]std.builtin.Type.Error{.{
            .name = "NotFound",
        }},
    });
    var e = @field(E, "NotFound");

https://github.com/ziglang/zig/issues/10710

billzez avatar Nov 05 '22 06:11 billzez