| author | |
| committer | |
| log | c7dc03fcb16abfac2d914002a609b8144f7cdab2 |
| tree | a1af2d48810cbdcd34b0904271e19d2248d62a27 |
| parent | 96931228af745b8e69c138b3b83893dafa166cfe |
| signature |
3 files changed, 51 insertions(+), 44 deletions(-)
src/ir.cpp+8-1| ... | @@ -3657,10 +3657,17 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3657,10 +3657,17 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3657 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) { | 3657 | if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) { |
| 3658 | IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); | 3658 | IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr); |
| 3659 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); | 3659 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 3660 | |||
| 3661 | ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1); | ||
| 3662 | result_loc_ret->base.id = ResultLocIdReturn; | ||
| 3663 | ir_build_reset_result(irb, scope, node, &result_loc_ret->base); | ||
| 3664 | ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base); | ||
| 3665 | |||
| 3660 | if (irb->codegen->have_err_ret_tracing && !should_inline) { | 3666 | if (irb->codegen->have_err_ret_tracing && !should_inline) { |
| 3661 | ir_build_save_err_ret_addr(irb, scope, node); | 3667 | ir_build_save_err_ret_addr(irb, scope, node); |
| 3662 | } | 3668 | } |
| 3663 | ir_gen_async_return(irb, scope, node, err_val, false); | 3669 | IrInstruction *ret_inst = ir_gen_async_return(irb, scope, node, err_val, false); |
| 3670 | result_loc_ret->base.source_instruction = ret_inst; | ||
| 3664 | } | 3671 | } |
| 3665 | 3672 | ||
| 3666 | ir_set_cursor_at_end_and_append_block(irb, continue_block); | 3673 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
test/stage1/behavior.zig+1-1| ... | @@ -47,7 +47,7 @@ comptime { | ... | @@ -47,7 +47,7 @@ comptime { |
| 47 | _ = @import("behavior/defer.zig"); | 47 | _ = @import("behavior/defer.zig"); |
| 48 | _ = @import("behavior/enum.zig"); | 48 | _ = @import("behavior/enum.zig"); |
| 49 | _ = @import("behavior/enum_with_members.zig"); | 49 | _ = @import("behavior/enum_with_members.zig"); |
| 50 | _ = @import("behavior/error.zig"); // TODO | 50 | _ = @import("behavior/error.zig"); |
| 51 | _ = @import("behavior/eval.zig"); | 51 | _ = @import("behavior/eval.zig"); |
| 52 | _ = @import("behavior/field_parent_ptr.zig"); | 52 | _ = @import("behavior/field_parent_ptr.zig"); |
| 53 | _ = @import("behavior/fn.zig"); | 53 | _ = @import("behavior/fn.zig"); |
test/stage1/behavior/error.zig+42-42| ... | @@ -249,48 +249,48 @@ fn intLiteral(str: []const u8) !?i64 { | ... | @@ -249,48 +249,48 @@ fn intLiteral(str: []const u8) !?i64 { |
| 249 | return error.T; | 249 | return error.T; |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | //test "nested error union function call in optional unwrap" { | 252 | test "nested error union function call in optional unwrap" { |
| 253 | // const S = struct { | 253 | const S = struct { |
| 254 | // const Foo = struct { | 254 | const Foo = struct { |
| 255 | // a: i32, | 255 | a: i32, |
| 256 | // }; | 256 | }; |
| 257 | // | 257 | |
| 258 | // fn errorable() !i32 { | 258 | fn errorable() !i32 { |
| 259 | // var x: Foo = (try getFoo()) orelse return error.Other; | 259 | var x: Foo = (try getFoo()) orelse return error.Other; |
| 260 | // return x.a; | 260 | return x.a; |
| 261 | // } | 261 | } |
| 262 | // | 262 | |
| 263 | // fn errorable2() !i32 { | 263 | fn errorable2() !i32 { |
| 264 | // var x: Foo = (try getFoo2()) orelse return error.Other; | 264 | var x: Foo = (try getFoo2()) orelse return error.Other; |
| 265 | // return x.a; | 265 | return x.a; |
| 266 | // } | 266 | } |
| 267 | // | 267 | |
| 268 | // fn errorable3() !i32 { | 268 | fn errorable3() !i32 { |
| 269 | // var x: Foo = (try getFoo3()) orelse return error.Other; | 269 | var x: Foo = (try getFoo3()) orelse return error.Other; |
| 270 | // return x.a; | 270 | return x.a; |
| 271 | // } | 271 | } |
| 272 | // | 272 | |
| 273 | // fn getFoo() anyerror!?Foo { | 273 | fn getFoo() anyerror!?Foo { |
| 274 | // return Foo{ .a = 1234 }; | 274 | return Foo{ .a = 1234 }; |
| 275 | // } | 275 | } |
| 276 | // | 276 | |
| 277 | // fn getFoo2() anyerror!?Foo { | 277 | fn getFoo2() anyerror!?Foo { |
| 278 | // return error.Failure; | 278 | return error.Failure; |
| 279 | // } | 279 | } |
| 280 | // | 280 | |
| 281 | // fn getFoo3() anyerror!?Foo { | 281 | fn getFoo3() anyerror!?Foo { |
| 282 | // return null; | 282 | return null; |
| 283 | // } | 283 | } |
| 284 | // }; | 284 | }; |
| 285 | // expect((try S.errorable()) == 1234); | 285 | expect((try S.errorable()) == 1234); |
| 286 | // expectError(error.Failure, S.errorable2()); | 286 | expectError(error.Failure, S.errorable2()); |
| 287 | // expectError(error.Other, S.errorable3()); | 287 | expectError(error.Other, S.errorable3()); |
| 288 | // comptime { | 288 | comptime { |
| 289 | // expect((try S.errorable()) == 1234); | 289 | expect((try S.errorable()) == 1234); |
| 290 | // expectError(error.Failure, S.errorable2()); | 290 | expectError(error.Failure, S.errorable2()); |
| 291 | // expectError(error.Other, S.errorable3()); | 291 | expectError(error.Other, S.errorable3()); |
| 292 | // } | 292 | } |
| 293 | //} | 293 | } |
| 294 | 294 | ||
| 295 | test "widen cast integer payload of error union function call" { | 295 | test "widen cast integer payload of error union function call" { |
| 296 | const S = struct { | 296 | const S = struct { |