From 3829e200ecc251d6b55686c24bdbd579c5a2246a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 18 Nov 2018 20:03:35 -0500 Subject: [PATCH] fix assertion failure related to @intToEnum --- src/ir.cpp | 2 +- test/cases/cast.zig | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index 3a22d0aa17..55f17b811d 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 06c029a405..bd45bbc00f 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); +}