Skip to content

decl literals not allowed as switch cases #24152

Open
@nektro

Description

@nektro

Zig Version

0.14.1, 0.15.0-dev.769+4d7980645

Steps to Reproduce and Observed Behavior

pub fn main() !void {
    var e: E = .foo;
    _ = &e;
    switch (e) {
        .bar => {},
        .foo => {},
        else => {},
    }
}

const E = enum(u8) {
    bar = 3,
    _,

    const foo: E = @enumFromInt(0xa);
};
test.zig:6:10: error: no field named 'foo' in enum 'test.E'
        .foo => {},
        ~^~~
test.zig:11:11: note: enum declared here
const E = enum(u8) {
          ^~~~
referenced by:
    callMain [inlined]: /zig/lib/std/start.zig:675:37
    callMainWithArgs [inlined]: /zig/lib/std/start.zig:635:20
    main: /zig/lib/std/start.zig:650:28

Expected Behavior

all test passed. with the following diff the test passes as initially expected since e is of type E:

-        .foo => {},
+        E.foo => {},

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions