authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-21 16:54:46-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-21 16:54:46-04:00
log5441f7767237709e8f3c05c2dc75070e835b4024
tree2143e4fd903bdb6e2f86af6aa93ea6bb5d7a04b0
parent142e77abbb8a88c2c6473921d0c600faf3d34a62
signaturelock-open Commit is signed but in an unrecognized format.

fix implicit cast bitcast result to error union by returning


2 files changed, 16 insertions(+), 0 deletions(-)

src/ir.cpp+3
...@@ -15207,6 +15207,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -15207,6 +15207,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
15207 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,15207 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
15208 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);15208 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1520915209
15210 if (value->value.special == ConstValSpecialRuntime) {
15211 parent_result_loc->value.special = ConstValSpecialRuntime;
15212 }
15210 result_loc->written = true;15213 result_loc->written = true;
15211 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,15214 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
15212 ptr_type, result_bit_cast->base.source_instruction, false);15215 ptr_type, result_bit_cast->base.source_instruction, false);
test/stage1/behavior/bitcast.zig+13
...@@ -112,3 +112,16 @@ test "bitcast packed struct to integer and back" {...@@ -112,3 +112,16 @@ test "bitcast packed struct to integer and back" {
112 S.doTheTest();112 S.doTheTest();
113 comptime S.doTheTest();113 comptime S.doTheTest();
114}114}
115
116test "implicit cast to error union by returning" {
117 const S = struct {
118 fn entry() void {
119 expect((func(-1) catch unreachable) == maxInt(u64));
120 }
121 pub fn func(sz: i64) anyerror!u64 {
122 return @bitCast(u64, sz);
123 }
124 };
125 S.entry();
126 comptime S.entry();
127}