diff --git a/src/ir.cpp b/src/ir.cpp index 3a22d0aa178110a50592e9834d670ce1994d59ab..55f17b811d8d9248bb382181abf2eaa8e08e1643 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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); diff --git a/test/cases/cast.zig b/test/cases/cast.zig index 06c029a405759864a6035b38bf3d07321e532f00..bd45bbc00f089ee1998b4327fe1ced55efc49e60 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -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); +}