fix assertion failure related to @intToEnum

This commit is contained in:
Andrew Kelley 2018-11-18 20:03:35 -05:00
parent 3c05ad4012
commit 3829e200ec
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 9 additions and 1 deletions

View File

@ -10153,7 +10153,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
return ira->codegen->invalid_instruction;
}
assert(actual_type->id == ZigTypeIdInt);
assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);

View File

@ -462,3 +462,11 @@ test "implicit cast comptime numbers to any type when the value fits" {
var b: u8 = a;
assert(b == 255);
}
test "@intToEnum passed a comptime_int to an enum with one item" {
const E = enum {
A,
};
const x = @intToEnum(E, 0);
assert(x == E.A);
}