fix implicit cast bitcast result to error union by returning

This commit is contained in:
Andrew Kelley 2019-06-21 16:54:46 -04:00
parent 142e77abbb
commit 5441f77672
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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();
}