fix: error on non-exhaustive enums with zero width backing type (#21374)

Co-authored-by: WillLillis <wlillis@umass.edu>
This commit is contained in:
Will Lillis 2025-02-01 22:36:16 -05:00 committed by GitHub
parent 963651bbf2
commit 953355ebea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 6 deletions

View file

@ -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;

View 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'