From d3426ce634a09ec289480510040b3decfbd38c39 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 29 Nov 2021 13:21:36 -0700 Subject: [PATCH] AstGen: require binary operations to have reachable operands --- src/AstGen.zig | 4 ++-- test/compile_errors.zig | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index ae66cae662..e132900c68 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -4781,8 +4781,8 @@ fn simpleBinOp( const node_datas = tree.nodes.items(.data); const result = try gz.addPlNode(op_inst_tag, node, Zir.Inst.Bin{ - .lhs = try expr(gz, scope, .none, node_datas[node].lhs), - .rhs = try expr(gz, scope, .none, node_datas[node].rhs), + .lhs = try reachableExpr(gz, scope, .none, node_datas[node].lhs, node), + .rhs = try reachableExpr(gz, scope, .none, node_datas[node].rhs, node), }); return rvalue(gz, rl, result, node); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 91b81c20e5..09a165304c 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -5033,13 +5033,18 @@ pub fn addCases(ctx: *TestContext) !void { "tmp.zig:2:5: note: control flow is diverted here", }); - ctx.objErrStage1("unreachable code - return return", + ctx.objErrStage1("unreachable code - multiple things", \\export fn a() i32 { \\ return return 1; \\} + \\export fn b(value: u32) bool { + \\ return 1 < value < 1000; + \\} , &[_][]const u8{ "tmp.zig:2:5: error: unreachable code", "tmp.zig:2:12: note: control flow is diverted here", + "tmp.zig:5:22: error: unreachable code", + "tmp.zig:5:5: note: control flow is diverted here", }); ctx.objErrStage1("bad import",