authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2019-05-10 05:23:26-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-10 10:05:40-04:00
logd065f297ab6de5ca35636d169195ce5da6235786
treed71cba76897f46dd77e0e83dd98ad500bc156be3
parent6b10f03b4a868cc02fc0535193ea0108c77ddd1f

stage1: compile error for loop expr val ignored

closes #2460

2 files changed, 20 insertions(+), 1 deletions(-)

src/ir.cpp+3-1
......@@ -5808,8 +5808,10 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
58085808
58095809 IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
58105810
5811 if (!instr_is_unreachable(body_result))
5811 if (!instr_is_unreachable(body_result)) {
5812 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result));
58125813 ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime));
5814 }
58135815
58145816 ir_set_cursor_at_end_and_append_block(irb, continue_block);
58155817 IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
test/compile_errors.zig+17
......@@ -5918,4 +5918,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
59185918 ,
59195919 "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'",
59205920 );
5921
5922 cases.add(
5923 "for loop body expression ignored",
5924 \\fn returns() usize {
5925 \\ return 2;
5926 \\}
5927 \\export fn f1() void {
5928 \\ for ("hello") |_| returns();
5929 \\}
5930 \\export fn f2() void {
5931 \\ var x: anyerror!i32 = error.Bad;
5932 \\ for ("hello") |_| returns() else unreachable;
5933 \\}
5934 ,
5935 "tmp.zig:5:30: error: expression value is ignored",
5936 "tmp.zig:9:30: error: expression value is ignored",
5937 );
59215938}