Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch exhaustion error has wrong type name #10535

Open
nektro opened this issue Jan 7, 2022 · 3 comments
Open

switch exhaustion error has wrong type name #10535

nektro opened this issue Jan 7, 2022 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@nektro
Copy link
Contributor

nektro commented Jan 7, 2022

Zig Version

0.10.0-dev.208+dd076d8cb

Steps to Reproduce

test {
    foo(u8);
}

fn foo(comptime T: type) void {
    return switch (@typeInfo(T)) {
        .Type => {},
        .Void => {},
        .Bool => {},
        .NoReturn => {},
        .Int => {},
        .Float => {},
        .Pointer => {},
        .Array => {},
        .Struct => {},
        .ComptimeFloat => {},
        .ComptimeInt => {},
        .Undefined => {},
        .Null => {},
        .Optional => {},
        .ErrorUnion => {},
        .ErrorSet => {},
        .Enum => {},
        .Union => {},
        .Fn => {},
        .BoundFn => {},
        .Opaque => {},
        .Frame => {},
        .AnyFrame => {},
        .Vector => {},
        // .EnumLiteral => {},
    };
}

Expected Behavior

./test.zig:6:12: error: enumeration value 'std.builtin.TypeInfo.EnumLiteral' not handled in switch
    return switch (@typeInfo(T)) {
           ^

Actual Behavior

./test.zig:6:12: error: enumeration value '@typeInfo(std.builtin.TypeInfo).Union.tag_type.?.EnumLiteral' not handled in switch
    return switch (@typeInfo(T)) {
           ^
@nektro nektro added the bug Observed behavior contradicts documented or intended behavior label Jan 7, 2022
@nektro nektro changed the title @typeInfo has wrong type name switch exhaustion error has wrong type name Jan 7, 2022
@Vexu Vexu added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. and removed bug Observed behavior contradicts documented or intended behavior labels Jan 9, 2022
@Vexu Vexu added this to the 0.11.0 milestone Jan 9, 2022
@enkore
Copy link
Contributor

enkore commented Jan 10, 2022

The expected behavior is nicer to read but as far as I can tell the actual behavior is not wrong, just verbose.

@nektro
Copy link
Contributor Author

nektro commented Jun 22, 2023

error now

test.zig:6:12: error: switch must handle all possibilities
    return switch (@typeInfo(T)) {
           ^~~~~~
/home/meghan/.local/share/zig/lib/std/builtin.zig:251:5: note: unhandled enumeration value: 'EnumLiteral'
    EnumLiteral: void,
    ^~~~~~~~~~~~~~~~~
/home/meghan/.local/share/zig/lib/std/builtin.zig:227:18: note: enum '@typeInfo(builtin.Type).Union.tag_type.?' declared here
pub const Type = union(enum) {
                 ^~~~~

@nektro
Copy link
Contributor Author

nektro commented Jun 22, 2023

note this is only happening because the union has an inferred tag type, so the ideal is still the title but status quo is acceptable

test {
    foo(.{ .a = 4 });
}

const E = enum {
    a,
    b,
    c,
};

const U = union(E) {
    a: u8,
    b: u16,
    c: u32,
};

fn foo(u: U) void {
    return switch (u) {
        .a => {},
        .b => {},
    };
}
test.zig:18:12: error: switch must handle all possibilities
    return switch (u) {
           ^~~~~~
test.zig:8:5: note: unhandled enumeration value: 'c'
    c,
    ^
test.zig:5:11: note: enum 'test.E' declared here
const E = enum {
          ^~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants