mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Fix @enumToInt and @tagName for auto-numbered enums with signed tag type.
This commit is contained in:
parent
b77679039f
commit
3267eb3a28
@ -448,7 +448,11 @@ pub const Key = union(enum) {
|
||||
if (x >= self.names.len) return null;
|
||||
return @intCast(u32, x);
|
||||
},
|
||||
.i64, .big_int => return null, // out of range
|
||||
.i64 => |x| {
|
||||
if (x >= self.names.len or x < 0) return null;
|
||||
return @intCast(u32, x);
|
||||
},
|
||||
.big_int => return null, // out of range
|
||||
.lazy_align, .lazy_size => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
@ -812,6 +812,11 @@ test "signed integer as enum tag" {
|
||||
try expect(@intFromEnum(SignedEnum.A2) == 1);
|
||||
}
|
||||
|
||||
test "int to enum with signed tag type" {
|
||||
const E = enum(i32) { a, b, c };
|
||||
try expect(@intToEnum(E, 0) == .a);
|
||||
}
|
||||
|
||||
test "enum with one member and custom tag type" {
|
||||
const E = enum(u2) {
|
||||
One,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user