fix several compile error test regressions

This commit is contained in:
Andrew Kelley 2019-06-25 18:06:03 -04:00
parent da68aec339
commit 0a77325916
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 52 additions and 34 deletions

View File

@ -5579,7 +5579,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");
IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");
IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, condition->source_node, condition,
IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
then_block, else_block, is_comptime);
ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
result_loc, is_comptime);
@ -5833,7 +5833,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
Buf *name = entry_node->data.struct_val_field.name;
AstNode *expr_node = entry_node->data.struct_val_field.expr;
IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, expr_node, container_ptr, name, true);
IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
result_loc_inst->base.id = ResultLocIdInstruction;
result_loc_inst->base.source_instruction = field_ptr;
@ -16822,11 +16822,6 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
peer_parent->done_resuming = true;
return ira_resume(ira);
}
if (peer_parent != nullptr && !peer_parent->skipped && peer_parent->base.resolved_loc != nullptr &&
type_is_invalid(peer_parent->base.resolved_loc->value.type))
{
return ira->codegen->invalid_instruction;
}
ZigList<IrBasicBlock*> new_incoming_blocks = {0};
ZigList<IrInstruction*> new_incoming_values = {0};
@ -17688,7 +17683,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);
return result;
}
} else if (is_array_ref(container_type)) {
} else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
if (buf_eql_str(field_name, "len")) {
ConstExprValue *len_val = create_const_vals(1);
if (container_type->id == ZigTypeIdPointer) {
@ -18003,6 +17998,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
return ira->codegen->invalid_instruction;
}
} else if (field_ptr_instruction->initializing) {
ir_add_error(ira, &field_ptr_instruction->base,
buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
return ira->codegen->invalid_instruction;
} else {
ir_add_error_node(ira, field_ptr_instruction->base.source_node,
buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
@ -24796,11 +24795,6 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
if (!was_written) {
IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
if (type_is_invalid(store_ptr->value.type)) {
instruction->result_loc->resolved_loc = ira->codegen->invalid_instruction;
if (instruction->result_loc->id == ResultLocIdPeer) {
reinterpret_cast<ResultLocPeer *>(instruction->result_loc)->parent->base.resolved_loc =
ira->codegen->invalid_instruction;
}
return ira->codegen->invalid_instruction;
}
}
@ -25198,7 +25192,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
old_instruction->child = new_instruction;
if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) {
if (type_is_invalid(new_instruction->value.type)) {
return ira->codegen->builtin_types.entry_invalid;
}

View File

@ -49,16 +49,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const Foo = struct {
\\ a: undefined,
\\};
\\const Bar = union {
\\ a: undefined,
\\};
\\pub fn main() void {
\\export fn entry1() void {
\\ const foo: Foo = undefined;
\\ const bar: Bar = undefined;
\\}
,
"tmp.zig:2:8: error: expected type 'type', found '(undefined)'",
"tmp.zig:5:8: error: expected type 'type', found '(undefined)'",
);
cases.add(
@ -461,13 +456,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const G = packed struct {
\\ x: Enum,
\\};
\\export fn entry() void {
\\export fn entry1() void {
\\ var a: A = undefined;
\\}
\\export fn entry2() void {
\\ var b: B = undefined;
\\}
\\export fn entry3() void {
\\ var r: C = undefined;
\\}
\\export fn entry4() void {
\\ var d: D = undefined;
\\}
\\export fn entry5() void {
\\ var e: E = undefined;
\\}
\\export fn entry6() void {
\\ var f: F = undefined;
\\}
\\export fn entry7() void {
\\ var g: G = undefined;
\\}
\\const S = struct {
@ -489,7 +496,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",
"tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
"tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",
"tmp.zig:38:14: note: enum declaration does not specify an integer tag type",
"tmp.zig:50:14: note: enum declaration does not specify an integer tag type",
);
cases.addCase(x: {
@ -721,7 +728,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var oops = @bitCast(u7, byte);
\\}
,
"tmp.zig:2:16: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
"tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
);
cases.add(
@ -1381,7 +1388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ for (xx) |f| {}
\\}
,
"tmp.zig:7:15: error: variable of type 'Foo' must be const or comptime",
"tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known",
);
cases.add(
@ -2250,6 +2257,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}
\\
\\extern fn bar(x: *void) void { }
\\export fn entry2() void {
\\ bar(&{});
\\}
,
"tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
"tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
@ -2576,7 +2586,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\
\\fn b() void {}
,
"tmp.zig:3:5: error: unreachable code",
"tmp.zig:3:6: error: unreachable code",
);
cases.add(
@ -2596,7 +2606,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}
,
"tmp.zig:3:5: error: use of undeclared identifier 'b'",
"tmp.zig:4:5: error: use of undeclared identifier 'c'",
);
cases.add(
@ -2662,7 +2671,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ const a: noreturn = {};
\\}
,
"tmp.zig:2:14: error: variable of type 'noreturn' not allowed",
"tmp.zig:2:25: error: expected type 'noreturn', found 'void'",
);
cases.add(
@ -2725,9 +2734,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var bad : bool = undefined;
\\ bad[bad] = bad[bad];
\\}
\\export fn g() void {
\\ var bad : bool = undefined;
\\ _ = bad[bad];
\\}
,
"tmp.zig:3:8: error: array access of non-array type 'bool'",
"tmp.zig:3:19: error: array access of non-array type 'bool'",
"tmp.zig:7:12: error: array access of non-array type 'bool'",
);
cases.add(
@ -2737,9 +2750,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var bad = false;
\\ array[bad] = array[bad];
\\}
\\export fn g() void {
\\ var array = "aoeu";
\\ var bad = false;
\\ _ = array[bad];
\\}
,
"tmp.zig:4:11: error: expected type 'usize', found 'bool'",
"tmp.zig:4:24: error: expected type 'usize', found 'bool'",
"tmp.zig:9:15: error: expected type 'usize', found 'bool'",
);
cases.add(
@ -2757,12 +2775,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"missing else clause",
\\fn f(b: bool) void {
\\ const x : i32 = if (b) h: { break :h 1; };
\\}
\\fn g(b: bool) void {
\\ const y = if (b) h: { break :h i32(1); };
\\}
\\export fn entry() void { f(true); }
\\export fn entry() void { f(true); g(true); }
,
"tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
"tmp.zig:3:15: error: incompatible types: 'i32' and 'void'",
"tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
);
cases.add(
@ -2773,9 +2793,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ a.foo = 1;
\\ const y = a.bar;
\\}
\\export fn g() void {
\\ var a : A = undefined;
\\ const y = a.bar;
\\}
,
"tmp.zig:4:6: error: no member named 'foo' in struct 'A'",
"tmp.zig:5:16: error: no member named 'bar' in struct 'A'",
"tmp.zig:9:16: error: no member named 'bar' in struct 'A'",
);
cases.add(
@ -2920,7 +2944,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ _ = foo;
\\}
,
"tmp.zig:1:19: error: type '[3]u16' does not support struct initialization syntax",
"tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax",
);
cases.add(
@ -3239,7 +3263,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\
\\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
,
"tmp.zig:5:25: error: unable to evaluate constant expression",
"tmp.zig:5:18: error: unable to evaluate constant expression",
"tmp.zig:2:12: note: called from here",
"tmp.zig:2:8: note: called from here",
);