Commit 5441f77672
Changed files (2)
src
test
stage1
behavior
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);
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();
+}