AstGen: require binary operations to have reachable operands

This commit is contained in:
Andrew Kelley 2021-11-29 13:21:36 -07:00
parent b613210140
commit d3426ce634
2 changed files with 8 additions and 3 deletions

View File

@ -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);
}

View File

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