authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-08 15:22:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-08 15:22:42-05:00
log028ec0f2c3574fb465ffe18f3022a7fa16f25ef6
treee410d1049af147ca64a15026703d3bb53900e736
parentaa9902b586ae5dacda9c10f4139cfceac00dcf22

enums with 1 field and explicit tag type still get the tag type

closes #820

2 files changed, 6 insertions(+), 1 deletions(-)

src/analyze.cpp+1-1
...@@ -2393,7 +2393,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2393,7 +2393,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2393 }2393 }
23942394
2395 enum_type->data.enumeration.zero_bits_loop_flag = false;2395 enum_type->data.enumeration.zero_bits_loop_flag = false;
2396 enum_type->zero_bits = (field_count < 2);2396 enum_type->zero_bits = !type_has_bits(tag_int_type);
2397 enum_type->data.enumeration.zero_bits_known = true;2397 enum_type->data.enumeration.zero_bits_known = true;
2398}2398}
23992399
test/cases/enum.zig+5
...@@ -387,3 +387,8 @@ const EnumWithTagValues = enum(u4) {...@@ -387,3 +387,8 @@ const EnumWithTagValues = enum(u4) {
387test "enum with tag values don't require parens" {387test "enum with tag values don't require parens" {
388 assert(u4(EnumWithTagValues.C) == 0b0100);388 assert(u4(EnumWithTagValues.C) == 0b0100);
389}389}
390
391test "enum with 1 field but explicit tag type should still have the tag type" {
392 const Enum = enum(u8) { B = 2 };
393 comptime @import("std").debug.assert(@sizeOf(Enum) == @sizeOf(u8));
394}