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...@@ -5462,8 +5462,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5462 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);5462 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
5463 if (expr_result == irb->codegen->invalid_instruction)5463 if (expr_result == irb->codegen->invalid_instruction)
5464 return expr_result;5464 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));
5466 ir_mark_gen(ir_build_br(irb, payload_scope, node, cond_block, is_comptime));5467 ir_mark_gen(ir_build_br(irb, payload_scope, node, cond_block, is_comptime));
5468 }
5467 }5469 }
54685470
5469 ir_set_cursor_at_end_and_append_block(irb, else_block);5471 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...@@ -5544,8 +5546,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5544 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);5546 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
5545 if (expr_result == irb->codegen->invalid_instruction)5547 if (expr_result == irb->codegen->invalid_instruction)
5546 return expr_result;5548 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));
5548 ir_mark_gen(ir_build_br(irb, child_scope, node, cond_block, is_comptime));5551 ir_mark_gen(ir_build_br(irb, child_scope, node, cond_block, is_comptime));
5552 }
5549 }5553 }
55505554
5551 IrInstruction *else_result = nullptr;5555 IrInstruction *else_result = nullptr;
...@@ -5609,8 +5613,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5609,8 +5613,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5609 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);5613 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
5610 if (expr_result == irb->codegen->invalid_instruction)5614 if (expr_result == irb->codegen->invalid_instruction)
5611 return expr_result;5615 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));
5613 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));5618 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));
5619 }
5614 }5620 }
56155621
5616 IrInstruction *else_result = nullptr;5622 IrInstruction *else_result = nullptr;
test/compile_errors.zig+22
...@@ -2,6 +2,28 @@ const tests = @import("tests.zig");...@@ -2,6 +2,28 @@ const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub 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
5 cases.add(27 cases.add(
6 "import outside package path",28 "import outside package path",
7 \\comptime{29 \\comptime{