zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 837cc467f7796bd098acce64f77b82060f4921e4 (tree)
parent e621ad014e919521268d3e2c94afadbdadadb59f
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Thu,  5 Jan 2017 19:05:48 -0500

pass array access compile error tests

Diffstat:
Msrc/ir.cpp | 10++++------
Mtest/run_tests.cpp | 25+++++++++++++++++++------
2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/ir.cpp b/src/ir.cpp @@ -119,7 +119,7 @@ static void ir_ref_bb(IrBasicBlock *bb) { static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) { assert(instruction->id != IrInstructionIdInvalid); instruction->ref_count += 1; - if (instruction->owner_bb != cur_bb) + if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction)) ir_ref_bb(instruction->owner_bb); } @@ -3112,12 +3112,10 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) { IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPurposeAssign); - if (lvalue == irb->codegen->invalid_instruction) - return lvalue; - IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope); - if (rvalue == irb->codegen->invalid_instruction) - return rvalue; + + if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction) + return irb->codegen->invalid_instruction; ir_build_store_ptr(irb, scope, node, lvalue, rvalue); return ir_build_const_void(irb, scope, node); diff --git a/test/run_tests.cpp b/test/run_tests.cpp @@ -808,16 +808,29 @@ fn f() { } )SOURCE", 1, ".tmp_source.zig:3:6: error: invalid token: 'const'"); - add_compile_fail_case("array access errors", R"SOURCE( + add_compile_fail_case("array access of undeclared identifier", R"SOURCE( fn f() { - var bad : bool = undefined; i[i] = i[i]; +} + )SOURCE", 2, ".tmp_source.zig:3:5: error: use of undeclared identifier 'i'", + ".tmp_source.zig:3:12: error: use of undeclared identifier 'i'"); + + add_compile_fail_case("array access of non array", R"SOURCE( +fn f() { + var bad : bool = undefined; bad[bad] = bad[bad]; } - )SOURCE", 4, ".tmp_source.zig:4:5: error: use of undeclared identifier 'i'", - ".tmp_source.zig:4:7: error: use of undeclared identifier 'i'", - ".tmp_source.zig:5:8: error: array access of non-array", - ".tmp_source.zig:5:9: error: expected type 'usize', found 'bool'"); + )SOURCE", 2, ".tmp_source.zig:4:8: error: array access of non-array type 'bool'", + ".tmp_source.zig:4:19: error: array access of non-array type 'bool'"); + + add_compile_fail_case("array access with non integer index", R"SOURCE( +fn f() { + var array = "aoeu"; + var bad = false; + array[bad] = array[bad]; +} + )SOURCE", 2, ".tmp_source.zig:5:11: error: expected type 'usize', found 'bool'", + ".tmp_source.zig:5:24: error: expected type 'usize', found 'bool'"); add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( fn f(...) {}