authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-18 20:03:35-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-11-18 20:04:16-05:00
log3829e200ecc251d6b55686c24bdbd579c5a2246a
tree6f7e67f54f17f15e67d694fb2bef4e74f8a13238
parent3c05ad401282b0eb8b9960a2b521fc1375c4087e
signaturelock-open Commit is signed but in an unrecognized format.

fix assertion failure related to @intToEnum


2 files changed, 9 insertions(+), 1 deletions(-)

src/ir.cpp+1-1
...@@ -10153,7 +10153,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -10153,7 +10153,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
10153 return ira->codegen->invalid_instruction;10153 return ira->codegen->invalid_instruction;
10154 }10154 }
1015510155
10156 assert(actual_type->id == ZigTypeIdInt);10156 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
1015710157
10158 if (instr_is_comptime(target)) {10158 if (instr_is_comptime(target)) {
10159 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);10159 ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
test/cases/cast.zig+8
...@@ -462,3 +462,11 @@ test "implicit cast comptime numbers to any type when the value fits" {...@@ -462,3 +462,11 @@ test "implicit cast comptime numbers to any type when the value fits" {
462 var b: u8 = a;462 var b: u8 = a;
463 assert(b == 255);463 assert(b == 255);
464}464}
465
466test "@intToEnum passed a comptime_int to an enum with one item" {
467 const E = enum {
468 A,
469 };
470 const x = @intToEnum(E, 0);
471 assert(x == E.A);
472}