mirror of
https://github.com/ziglang/zig.git
synced 2024-12-03 10:28:48 +00:00
pass array access compile error tests
This commit is contained in:
parent
e621ad014e
commit
837cc467f7
10
src/ir.cpp
10
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);
|
||||
|
@ -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() {
|
||||
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;
|
||||
i[i] = i[i];
|
||||
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(...) {}
|
||||
|
Loading…
Reference in New Issue
Block a user