authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-11 13:43:44-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-11 13:43:44-04:00
logb87686dfa094770e96da33fb23a7d011a168157c
treeaad9a7a04a0499d5ebf4782c943ae0f95736b85d
parent1b83ee78a48a64bef28f12b7b2e263074f88b6b6
signaturelock-open Commit is signed but in an unrecognized format.

fix enum with one member and custom tag type


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

src/ir.cpp-1
...@@ -11938,7 +11938,6 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -11938,7 +11938,6 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
11938 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&11938 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&
11939 enum_type->data.enumeration.src_field_count == 1)11939 enum_type->data.enumeration.src_field_count == 1)
11940 {11940 {
11941 assert(tag_type == ira->codegen->builtin_types.entry_num_lit_int);
11942 IrInstruction *result = ir_const(ira, source_instr, tag_type);11941 IrInstruction *result = ir_const(ira, source_instr, tag_type);
11943 init_const_bigint(&result->value, tag_type,11942 init_const_bigint(&result->value, tag_type,
11944 &enum_type->data.enumeration.fields[0].value);11943 &enum_type->data.enumeration.fields[0].value);
test/stage1/behavior/enum.zig+11
...@@ -982,3 +982,14 @@ test "enum literal casting to tagged union" {...@@ -982,3 +982,14 @@ test "enum literal casting to tagged union" {
982 else => @panic("fail"),982 else => @panic("fail"),
983 }983 }
984}984}
985
986test "enum with one member and custom tag type" {
987 const E = enum(u2) {
988 One,
989 };
990 expect(@enumToInt(E.One) == 0);
991 const E2 = enum(u2) {
992 One = 2,
993 };
994 expect(@enumToInt(E2.One) == 2);
995}