Commit 1c4c68e6ba

Veikka Tuominen <git@vexu.eu>
2022-09-02 13:16:27
AstGen: use reachableExpr for try operand
Closes #12248
1 parent db54cd2
Changed files (2)
src
test
cases
compile_errors
src/AstGen.zig
@@ -5127,7 +5127,7 @@ fn tryExpr(
         else => .none,
     };
     // This could be a pointer or value depending on the `rl` parameter.
-    const operand = try expr(parent_gz, scope, operand_rl, operand_node);
+    const operand = try reachableExpr(parent_gz, scope, operand_rl, operand_node, node);
     const is_inline = parent_gz.force_comptime;
     const is_inline_bit = @as(u2, @boolToInt(is_inline));
     const is_ptr_bit = @as(u2, @boolToInt(operand_rl == .ref)) << 1;
test/cases/compile_errors/try_return.zig
@@ -0,0 +1,11 @@
+pub fn foo() !void {
+    try return bar();
+}
+pub fn bar() !void {}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:5: error: unreachable code
+// :2:9: note: control flow is diverted here