Skip to content

Commit

Permalink
enums with 1 field and explicit tag type still get the tag type
Browse files Browse the repository at this point in the history
closes #820
  • Loading branch information
andrewrk committed Mar 8, 2018
1 parent aa9902b commit 028ec0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/analyze.cpp
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions test/cases/enum.zig
Expand Up @@ -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));
}

0 comments on commit 028ec0f

Please sign in to comment.