From 1c4c68e6ba058f0c320f222275335245305974a0 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 2 Sep 2022 14:16:27 +0300 Subject: [PATCH] AstGen: use reachableExpr for try operand Closes #12248 --- src/AstGen.zig | 2 +- test/cases/compile_errors/try_return.zig | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/cases/compile_errors/try_return.zig diff --git a/src/AstGen.zig b/src/AstGen.zig index 79e5ad963e9efb63edf914cb35de507b7841c951..1502b970178a9c6813605f7843fd4ad48c2b1d04 100644 --- a/src/AstGen.zig +++ b/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; diff --git a/test/cases/compile_errors/try_return.zig b/test/cases/compile_errors/try_return.zig new file mode 100644 index 0000000000000000000000000000000000000000..61e71e72b57c38a081818486971e9087771f7d99 --- /dev/null +++ b/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 -- 2.54.0