authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-02 14:16:27+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-02 17:57:10+03:00
log1c4c68e6ba058f0c320f222275335245305974a0
treedf38ca766ddfb85723b9cab92be6f3f16531a58b
parentdb54cd247ddb8bf7b4225eaaf1e7a851151f8f0b

AstGen: use reachableExpr for try operand

Closes #12248

2 files changed, 12 insertions(+), 1 deletions(-)

src/AstGen.zig+1-1
......@@ -5127,7 +5127,7 @@ fn tryExpr(
51275127 else => .none,
51285128 };
51295129 // This could be a pointer or value depending on the `rl` parameter.
5130 const operand = try expr(parent_gz, scope, operand_rl, operand_node);
5130 const operand = try reachableExpr(parent_gz, scope, operand_rl, operand_node, node);
51315131 const is_inline = parent_gz.force_comptime;
51325132 const is_inline_bit = @as(u2, @boolToInt(is_inline));
51335133 const is_ptr_bit = @as(u2, @boolToInt(operand_rl == .ref)) << 1;
test/cases/compile_errors/try_return.zig created+11
......@@ -0,0 +1,11 @@
1pub fn foo() !void {
2 try return bar();
3}
4pub fn bar() !void {}
5
6// error
7// backend=stage2
8// target=native
9//
10// :2:5: error: unreachable code
11// :2:9: note: control flow is diverted here