fix enum with one member and custom tag type

This commit is contained in:
Andrew Kelley 2019-08-11 13:43:44 -04:00
parent 1b83ee78a4
commit b87686dfa0
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 11 additions and 1 deletions

View File

@ -11938,7 +11938,6 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&
enum_type->data.enumeration.src_field_count == 1)
{
assert(tag_type == ira->codegen->builtin_types.entry_num_lit_int);
IrInstruction *result = ir_const(ira, source_instr, tag_type);
init_const_bigint(&result->value, tag_type,
&enum_type->data.enumeration.fields[0].value);

View File

@ -982,3 +982,14 @@ test "enum literal casting to tagged union" {
else => @panic("fail"),
}
}
test "enum with one member and custom tag type" {
const E = enum(u2) {
One,
};
expect(@enumToInt(E.One) == 0);
const E2 = enum(u2) {
One = 2,
};
expect(@enumToInt(E2.One) == 2);
}