From 5441f7767237709e8f3c05c2dc75070e835b4024 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 21 Jun 2019 16:54:46 -0400 Subject: [PATCH] fix implicit cast bitcast result to error union by returning --- src/ir.cpp | 3 +++ test/stage1/behavior/bitcast.zig | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index 7b6f2dffe6..425c225308 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15207,6 +15207,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle, parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); + if (value->value.special == ConstValSpecialRuntime) { + parent_result_loc->value.special = ConstValSpecialRuntime; + } result_loc->written = true; result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, ptr_type, result_bit_cast->base.source_instruction, false); diff --git a/test/stage1/behavior/bitcast.zig b/test/stage1/behavior/bitcast.zig index e86c50885e..394ade1a21 100644 --- a/test/stage1/behavior/bitcast.zig +++ b/test/stage1/behavior/bitcast.zig @@ -112,3 +112,16 @@ test "bitcast packed struct to integer and back" { S.doTheTest(); comptime S.doTheTest(); } + +test "implicit cast to error union by returning" { + const S = struct { + fn entry() void { + expect((func(-1) catch unreachable) == maxInt(u64)); + } + pub fn func(sz: i64) anyerror!u64 { + return @bitCast(u64, sz); + } + }; + S.entry(); + comptime S.entry(); +}