Commit 3829e200ec

Andrew Kelley <superjoe30@gmail.com>
2018-11-19 02:03:35
fix assertion failure related to @intToEnum
1 parent 3c05ad4
Changed files (2)
src
test
cases
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);
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);
+}