mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
fix: error on non-exhaustive enums with zero width backing type (#21374)
Co-authored-by: WillLillis <wlillis@umass.edu>
This commit is contained in:
parent
963651bbf2
commit
953355ebea
2 changed files with 22 additions and 6 deletions
11
src/Sema.zig
11
src/Sema.zig
|
|
@ -38436,12 +38436,6 @@ fn resolveDeclaredEnumInner(
|
|||
|
||||
wip_ty.setTagTy(ip, int_tag_ty.toIntern());
|
||||
|
||||
if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) {
|
||||
if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(zcu)) {
|
||||
return sema.fail(block, src, "non-exhaustive enum specifies every value", .{});
|
||||
}
|
||||
}
|
||||
|
||||
var extra_index = body_end + bit_bags_count;
|
||||
var bit_bag_index: usize = body_end;
|
||||
var cur_bit_bag: u32 = undefined;
|
||||
|
|
@ -38528,6 +38522,11 @@ fn resolveDeclaredEnumInner(
|
|||
return sema.failWithOwnedErrorMsg(block, msg);
|
||||
}
|
||||
}
|
||||
if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) {
|
||||
if (fields_len >= 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(zcu)) {
|
||||
return sema.fail(block, src, "non-exhaustive enum specifies every value", .{});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
|
||||
|
|
|
|||
17
test/cases/compile_errors/zero_width_nonexhaustive_enum.zig
Normal file
17
test/cases/compile_errors/zero_width_nonexhaustive_enum.zig
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
comptime {
|
||||
_ = enum(i0) { a, _ };
|
||||
}
|
||||
|
||||
comptime {
|
||||
_ = enum(u0) { a, _ };
|
||||
}
|
||||
|
||||
comptime {
|
||||
_ = enum(u0) { a, b, _ };
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :2:9: error: non-exhaustive enum specifies every value
|
||||
// :6:9: error: non-exhaustive enum specifies every value
|
||||
// :10:23: error: enumeration value '1' too large for type 'u0'
|
||||
Loading…
Add table
Reference in a new issue