authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-05 19:05:48-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-05 19:05:48-05:00
log837cc467f7796bd098acce64f77b82060f4921e4
treefacf21b4501670fa2e87bae28076456ba00b442e
parente621ad014e919521268d3e2c94afadbdadadb59f

pass array access compile error tests


2 files changed, 23 insertions(+), 12 deletions(-)

src/ir.cpp+4-6
......@@ -119,7 +119,7 @@ static void ir_ref_bb(IrBasicBlock *bb) {
119119static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {
120120 assert(instruction->id != IrInstructionIdInvalid);
121121 instruction->ref_count += 1;
122 if (instruction->owner_bb != cur_bb)
122 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
123123 ir_ref_bb(instruction->owner_bb);
124124}
125125
......@@ -3112,12 +3112,10 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no
31123112
31133113static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
31143114 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPurposeAssign);
3115 if (lvalue == irb->codegen->invalid_instruction)
3116 return lvalue;
3117
31183115 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3119 if (rvalue == irb->codegen->invalid_instruction)
3120 return rvalue;
3116
3117 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)
3118 return irb->codegen->invalid_instruction;
31213119
31223120 ir_build_store_ptr(irb, scope, node, lvalue, rvalue);
31233121 return ir_build_const_void(irb, scope, node);
test/run_tests.cpp+19-6
......@@ -808,16 +808,29 @@ fn f() {
808808}
809809 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");
810810
811 add_compile_fail_case("array access errors", R"SOURCE(
811 add_compile_fail_case("array access of undeclared identifier", R"SOURCE(
812812fn f() {
813 var bad : bool = undefined;
814813 i[i] = i[i];
814}
815 )SOURCE", 2, ".tmp_source.zig:3:5: error: use of undeclared identifier 'i'",
816 ".tmp_source.zig:3:12: error: use of undeclared identifier 'i'");
817
818 add_compile_fail_case("array access of non array", R"SOURCE(
819fn f() {
820 var bad : bool = undefined;
815821 bad[bad] = bad[bad];
816822}
817 )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",
818 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",
819 ".tmp_source.zig:5:8: error: array access of non-array",
820 ".tmp_source.zig:5:9: error: expected type 'usize', found 'bool'");
823 )SOURCE", 2, ".tmp_source.zig:4:8: error: array access of non-array type 'bool'",
824 ".tmp_source.zig:4:19: error: array access of non-array type 'bool'");
825
826 add_compile_fail_case("array access with non integer index", R"SOURCE(
827fn f() {
828 var array = "aoeu";
829 var bad = false;
830 array[bad] = array[bad];
831}
832 )SOURCE", 2, ".tmp_source.zig:5:11: error: expected type 'usize', found 'bool'",
833 ".tmp_source.zig:5:24: error: expected type 'usize', found 'bool'");
821834
822835 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
823836fn f(...) {}