authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-15 23:52:11-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-15 23:52:11-04:00
log4a5cd0b895d0c6093fa710ed4ecb819726b58c25
tree4f503a89800bb6b7feb75e951fe4f28d7f87e670
parent01fb42103115a58c4b693a600dc5379fedb4ea86
signaturelock-open Commit is signed but in an unrecognized format.

fix while continue block not checking for ignored expression

closes #957

2 files changed, 31 insertions(+), 3 deletions(-)

src/ir.cpp+9-3
......@@ -5462,8 +5462,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
54625462 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
54635463 if (expr_result == irb->codegen->invalid_instruction)
54645464 return expr_result;
5465 if (!instr_is_unreachable(expr_result))
5465 if (!instr_is_unreachable(expr_result)) {
5466 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));
54665467 ir_mark_gen(ir_build_br(irb, payload_scope, node, cond_block, is_comptime));
5468 }
54675469 }
54685470
54695471 ir_set_cursor_at_end_and_append_block(irb, else_block);
......@@ -5544,8 +5546,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
55445546 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
55455547 if (expr_result == irb->codegen->invalid_instruction)
55465548 return expr_result;
5547 if (!instr_is_unreachable(expr_result))
5549 if (!instr_is_unreachable(expr_result)) {
5550 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));
55485551 ir_mark_gen(ir_build_br(irb, child_scope, node, cond_block, is_comptime));
5552 }
55495553 }
55505554
55515555 IrInstruction *else_result = nullptr;
......@@ -5609,8 +5613,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
56095613 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
56105614 if (expr_result == irb->codegen->invalid_instruction)
56115615 return expr_result;
5612 if (!instr_is_unreachable(expr_result))
5616 if (!instr_is_unreachable(expr_result)) {
5617 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));
56135618 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));
5619 }
56145620 }
56155621
56165622 IrInstruction *else_result = nullptr;
test/compile_errors.zig+22
......@@ -2,6 +2,28 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "ignored expression in while continuation",
7 \\export fn a() void {
8 \\ while (true) : (bad()) {}
9 \\}
10 \\export fn b() void {
11 \\ var x: anyerror!i32 = 1234;
12 \\ while (x) |_| : (bad()) {} else |_| {}
13 \\}
14 \\export fn c() void {
15 \\ var x: ?i32 = 1234;
16 \\ while (x) |_| : (bad()) {}
17 \\}
18 \\fn bad() anyerror!void {
19 \\ return error.Bad;
20 \\}
21 ,
22 "tmp.zig:2:24: error: expression value is ignored",
23 "tmp.zig:6:25: error: expression value is ignored",
24 "tmp.zig:10:25: error: expression value is ignored",
25 );
26
527 cases.add(
628 "import outside package path",
729 \\comptime{