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) {...@@ -119,7 +119,7 @@ static void ir_ref_bb(IrBasicBlock *bb) {
119static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {119static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {
120 assert(instruction->id != IrInstructionIdInvalid);120 assert(instruction->id != IrInstructionIdInvalid);
121 instruction->ref_count += 1;121 instruction->ref_count += 1;
122 if (instruction->owner_bb != cur_bb)122 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
123 ir_ref_bb(instruction->owner_bb);123 ir_ref_bb(instruction->owner_bb);
124}124}
125125
...@@ -3112,12 +3112,10 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no...@@ -3112,12 +3112,10 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no
31123112
3113static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {3113static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
3114 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPurposeAssign);3114 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
3118 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);3115 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
3119 if (rvalue == irb->codegen->invalid_instruction)3116
3120 return rvalue;3117 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)
3118 return irb->codegen->invalid_instruction;
31213119
3122 ir_build_store_ptr(irb, scope, node, lvalue, rvalue);3120 ir_build_store_ptr(irb, scope, node, lvalue, rvalue);
3123 return ir_build_const_void(irb, scope, node);3121 return ir_build_const_void(irb, scope, node);
test/run_tests.cpp+19-6
...@@ -808,16 +808,29 @@ fn f() {...@@ -808,16 +808,29 @@ fn f() {
808}808}
809 )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'");809 )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(
812fn f() {812fn f() {
813 var bad : bool = undefined;
814 i[i] = i[i];813 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;
815 bad[bad] = bad[bad];821 bad[bad] = bad[bad];
816}822}
817 )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'",823 )SOURCE", 2, ".tmp_source.zig:4:8: error: array access of non-array type 'bool'",
818 ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'",824 ".tmp_source.zig:4:19: error: array access of non-array type 'bool'");
819 ".tmp_source.zig:5:8: error: array access of non-array",825
820 ".tmp_source.zig:5:9: error: expected type 'usize', found 'bool'");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
822 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(835 add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE(
823fn f(...) {}836fn f(...) {}