-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
values of type '(enum literal)' must be comptime known #4629
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
Comments
The type inferencer has a hard time with nested expressions: |
Just confirming, this is a bug. It's fixed in stage 2. |
Updating the code so that it builds with the latest version of zig const std = @import("std");
const Mode = enum { Low, Medium, High, Custom };
pub fn main() void {
var xoroshiro = std.rand.Xoroshiro128.init(@intCast(std.time.milliTimestamp()));
var random = xoroshiro.random();
const i: usize = 5;
const mode: Mode = switch (i) {
0 => .Custom,
else => blk: {
break :blk switch (random.intRangeAtMost(u8, 0, 100)) {
0...33 => .Low,
34...66 => .Medium,
67...100 => .High,
else => unreachable,
};
},
};
std.debug.print("{}\n", .{mode});
} This now works, going ahead and closing the issue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working:
Not working:
Something wrong with inferring types and nested switches, maybe?
The text was updated successfully, but these errors were encountered: