We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
@intToEnum
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
0.11.0-dev.1026+4172c2916
// enum.zig const std = @import("std"); pub fn main() void { const E = enum(u3) { a, b, c, _ }; std.debug.print("{}, {}\n", .{ @intToEnum(E, 100), @intToEnum(E, 101), }); }
$ zig run enum.zig enum.main.E(4), enum.main.E(5)
It currently seems to just mask off the upper bits without checking that 100 is representable in a u3.
100
u3
A safety check of some kind as documented here
Attempting to convert an integer which represents no value in the chosen enum type invokes safety-checked Undefined Behavior.
Furthermore, @intToEnum should arguably take the tag type of the given enumeration rather than anytype to prevent this at the type level.
anytype
@intToEnum(comptime DestType: type, integer: anytype) DestType // vs. @intToEnum(comptime DestType: type, integer: std.meta.Tag(DestType)) DestType
Possibly related:
invalid enum value
enum
The text was updated successfully, but these errors were encountered:
This was intentionally changed in bb38931
Possibly related: invalid enum value not always detected where enum size is not explicit #11761
That is a runtime bug and this is a comptime bug, similar but unrelated.
Sorry, something went wrong.
332a438
Sema: @intToEnum on non-exhaustive enum at comptime should check in…
67d118f
…t is in range Closes ziglang#14155
No branches or pull requests
Zig Version
0.11.0-dev.1026+4172c2916
Steps to Reproduce and Observed Behavior
It currently seems to just mask off the upper bits without checking that
100
is representable in au3
.Expected Behavior
A safety check of some kind as documented here
Furthermore,
@intToEnum
should arguably take the tag type of the given enumeration rather thananytype
to prevent this at the type level.Possibly related:
invalid enum value
not always detected whereenum
size is not explicit #11761The text was updated successfully, but these errors were encountered: