aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-03-08 15:22:42 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-03-08 15:22:42 -0500
commit028ec0f2c3574fb465ffe18f3022a7fa16f25ef6 (patch)
treee410d1049af147ca64a15026703d3bb53900e736
parentaa9902b586ae5dacda9c10f4139cfceac00dcf22 (diff)
downloadzig-028ec0f2c3574fb465ffe18f3022a7fa16f25ef6.tar.gz
zig-028ec0f2c3574fb465ffe18f3022a7fa16f25ef6.zip
enums with 1 field and explicit tag type still get the tag type
closes #820
-rw-r--r--src/analyze.cpp2
-rw-r--r--test/cases/enum.zig5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 74dfd003d9..37b2798f3e 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -2393,7 +2393,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
}
enum_type->data.enumeration.zero_bits_loop_flag = false;
- enum_type->zero_bits = (field_count < 2);
+ enum_type->zero_bits = !type_has_bits(tag_int_type);
enum_type->data.enumeration.zero_bits_known = true;
}
diff --git a/test/cases/enum.zig b/test/cases/enum.zig
index 8020e593f8..644c989b04 100644
--- a/test/cases/enum.zig
+++ b/test/cases/enum.zig
@@ -387,3 +387,8 @@ const EnumWithTagValues = enum(u4) {
test "enum with tag values don't require parens" {
assert(u4(EnumWithTagValues.C) == 0b0100);
}
+
+test "enum with 1 field but explicit tag type should still have the tag type" {
+ const Enum = enum(u8) { B = 2 };
+ comptime @import("std").debug.assert(@sizeOf(Enum) == @sizeOf(u8));
+}