Skip to content

switch + if + enum confused the compiler #10559

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

Closed
ayende opened this issue Jan 10, 2022 · 1 comment
Closed

switch + if + enum confused the compiler #10559

ayende opened this issue Jan 10, 2022 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@ayende
Copy link
Contributor

ayende commented Jan 10, 2022

Zig Version

0.9.0

Steps to Reproduce

Try to compile the following code (https://godbolt.org/z/b5fj6dhxG):

pub const Num = enum{Even,Odd};

fn isEven(a: u32) Num {
    return switch(a) {
       3 => if (a & 1 != 0 ) .Odd else .Even,
       else => .Even
    };
}

Expected Behavior

Should compile successfully

Actual Behavior

/example.zig:23:13: error: values of type '@Type(.EnumLiteral)' must be comptime known
       3 => if (a & 1 != 0 ) .Odd else .Even,
            ^
@ayende ayende added the bug Observed behavior contradicts documented or intended behavior label Jan 10, 2022
@Vexu
Copy link
Member

Vexu commented Jan 10, 2022

Duplicate of #3750, fixed in the self hosted compiler.

@Vexu Vexu closed this as completed Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants