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

@enumFromInt doesnt safety check out of range int on non-exhaustive enum #21946

Open
xdBronch opened this issue Nov 9, 2024 · 0 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@xdBronch
Copy link
Contributor

xdBronch commented Nov 9, 2024

Zig Version

0.14.0-dev.2162+3054486d1

Steps to Reproduce and Observed Behavior

pub fn main() !void {
    var a: i8 = -1;
    _ = &a;
    const b: enum(u4) { _ } = @enumFromInt(a);
    _ = b;
}

this incorrectly passes and gives b an enum value of 15, just reinterpreting the lower bits. if a is comptime known it errors as expected

Expected Behavior

runtime panic invalid enum value

@xdBronch xdBronch added the bug Observed behavior contradicts documented or intended behavior label Nov 9, 2024
@mlugg mlugg added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Nov 9, 2024
@mlugg mlugg added this to the 0.14.0 milestone Nov 9, 2024
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants