diff --git a/src/Sema.zig b/src/Sema.zig index b50faa4b9b593799437e08a29ebbc4f16b89f7a3..30db9e90009bf854f464f2dbe8af3863b38db0c4 100644 --- a/src/Sema.zig +++ b/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; diff --git a/test/cases/compile_errors/zero_width_nonexhaustive_enum.zig b/test/cases/compile_errors/zero_width_nonexhaustive_enum.zig new file mode 100644 index 0000000000000000000000000000000000000000..a38c5f357adc794b0049473eea29e636bbad0203 --- /dev/null +++ b/test/cases/compile_errors/zero_width_nonexhaustive_enum.zig @@ -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'