zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit d3426ce634a09ec289480510040b3decfbd38c39 (tree)
parent b613210140f649b11232fae8bad16867d122d0cb
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 29 Nov 2021 13:21:36 -0700

AstGen: require binary operations to have reachable operands

Diffstat:
Msrc/AstGen.zig | 4++--
Mtest/compile_errors.zig | 7++++++-
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git 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 @@ -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",