authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-09 22:34:34-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-09 22:34:34-05:00
log5ea79bfc4a0a1269930d98faee36a8f6cb0b0401
treee69f01abb631fb64fa95556a70d300f41d5b3521
parent04ee3b01a159a25894f93d8448fb766ae545ab53
signaturelock-open Commit is signed but in an unrecognized format.

fix not checking type of return pointer

Thanks to Vexu for the test cases. Closes #3422 Closes #3646 Closes #3224 Closes #3327 Closes #3269

2 files changed, 36 insertions(+), 0 deletions(-)

src/ir.cpp+12
...@@ -19591,6 +19591,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19591,6 +19591,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19591 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {19591 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
19592 return result_loc;19592 return result_loc;
19593 }19593 }
19594 IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type);
19595 dummy_value->value->special = ConstValSpecialRuntime;
19596 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,
19597 dummy_value, result_loc->value->type->data.pointer.child_type);
19598 if (type_is_invalid(dummy_result->value->type))
19599 return ira->codegen->invalid_inst_gen;
19594 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;19600 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
19595 if (res_child_type == ira->codegen->builtin_types.entry_var) {19601 if (res_child_type == ira->codegen->builtin_types.entry_var) {
19596 res_child_type = impl_fn_type_id->return_type;19602 res_child_type = impl_fn_type_id->return_type;
...@@ -19723,6 +19729,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19723,6 +19729,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19723 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {19729 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
19724 return result_loc;19730 return result_loc;
19725 }19731 }
19732 IrInstGen *dummy_value = ir_const(ira, source_instr, return_type);
19733 dummy_value->value->special = ConstValSpecialRuntime;
19734 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,
19735 dummy_value, result_loc->value->type->data.pointer.child_type);
19736 if (type_is_invalid(dummy_result->value->type))
19737 return ira->codegen->invalid_inst_gen;
19726 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;19738 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
19727 if (res_child_type == ira->codegen->builtin_types.entry_var) {19739 if (res_child_type == ira->codegen->builtin_types.entry_var) {
19728 res_child_type = return_type;19740 res_child_type = return_type;
test/compile_errors.zig+24
...@@ -3,6 +3,30 @@ const builtin = @import("builtin");...@@ -3,6 +3,30 @@ const builtin = @import("builtin");
3const Target = @import("std").Target;3const Target = @import("std").Target;
44
5pub fn addCases(cases: *tests.CompileErrorContext) void {5pub fn addCases(cases: *tests.CompileErrorContext) void {
6 cases.add("function call assigned to incorrect type",
7 \\export fn entry() void {
8 \\ var arr: [4]f32 = undefined;
9 \\ arr = concat();
10 \\}
11 \\fn concat() [16]f32 {
12 \\ return [1]f32{0}**16;
13 \\}
14 , &[_][]const u8{
15 "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'",
16 });
17
18 cases.add("generic function call assigned to incorrect type",
19 \\pub export fn entry() void {
20 \\ var res: []i32 = undefined;
21 \\ res = myAlloc(i32);
22 \\}
23 \\fn myAlloc(comptime arg: type) anyerror!arg{
24 \\ unreachable;
25 \\}
26 , &[_][]const u8{
27 "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32",
28 });
29
6 cases.addTest("dependency loop in top-level decl with @TypeInfo",30 cases.addTest("dependency loop in top-level decl with @TypeInfo",
7 \\export const foo = @typeInfo(@This());31 \\export const foo = @typeInfo(@This());
8 , &[_][]const u8{32 , &[_][]const u8{