| author | |
| committer | |
| log | e7cc45642138472c29e09cd10e31962426c1aba5 |
| tree | 24c9aad00056e2a31e7d1509d9f4924fc77c3222 |
| parent | 7782c76bee0201227be730ae131171939f728538 |
3 files changed, 22 insertions(+), 4 deletions(-)
src/analyze.cpp+1-1| ... | @@ -1957,7 +1957,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc | ... | @@ -1957,7 +1957,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1957 | 1957 | ||
| 1958 | if(!is_valid_return_type(specified_return_type)){ | 1958 | if(!is_valid_return_type(specified_return_type)){ |
| 1959 | ErrorMsg* msg = add_node_error(g, fn_proto->return_type, | 1959 | ErrorMsg* msg = add_node_error(g, fn_proto->return_type, |
| 1960 | buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name))); | 1960 | buf_sprintf("%s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name))); |
| 1961 | Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name); | 1961 | Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name); |
| 1962 | if (tld != nullptr) { | 1962 | if (tld != nullptr) { |
| 1963 | add_error_note(g, msg, tld->source_node, buf_sprintf("type declared here")); | 1963 | add_error_note(g, msg, tld->source_node, buf_sprintf("type declared here")); |
src/ir.cpp+1-1| ... | @@ -19342,7 +19342,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, | ... | @@ -19342,7 +19342,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 19342 | 19342 | ||
| 19343 | if(!is_valid_return_type(specified_return_type)){ | 19343 | if(!is_valid_return_type(specified_return_type)){ |
| 19344 | ErrorMsg *msg = ir_add_error(ira, source_instr, | 19344 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 19345 | buf_sprintf("call to generic function with return type '%s' not allowed", buf_ptr(&specified_return_type->name))); | 19345 | buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name))); |
| 19346 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here")); | 19346 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here")); |
| 19347 | 19347 | ||
| 19348 | Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name); | 19348 | Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name); |
test/compile_errors.zig+20-2| ... | @@ -6538,9 +6538,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6538,9 +6538,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6538 | \\export fn bar() !FooType { | 6538 | \\export fn bar() !FooType { |
| 6539 | \\ return error.InvalidValue; | 6539 | \\ return error.InvalidValue; |
| 6540 | \\} | 6540 | \\} |
| 6541 | \\export fn bav() !@TypeOf(null) { | ||
| 6542 | \\ return error.InvalidValue; | ||
| 6543 | \\} | ||
| 6544 | \\export fn baz() !@TypeOf(undefined) { | ||
| 6545 | \\ return error.InvalidValue; | ||
| 6546 | \\} | ||
| 6541 | , &[_][]const u8{ | 6547 | , &[_][]const u8{ |
| 6542 | "tmp.zig:2:18: error: return type 'FooType' not allowed", | 6548 | "tmp.zig:2:18: error: Opaque return type 'FooType' not allowed", |
| 6543 | "tmp.zig:1:1: note: type declared here", | 6549 | "tmp.zig:1:1: note: type declared here", |
| 6550 | "tmp.zig:5:18: error: Null return type '(null)' not allowed", | ||
| 6551 | "tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed", | ||
| 6544 | }); | 6552 | }); |
| 6545 | 6553 | ||
| 6546 | cases.add("generic function returning opaque type", | 6554 | cases.add("generic function returning opaque type", |
| ... | @@ -6551,10 +6559,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6551,10 +6559,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6551 | \\export fn bar() void { | 6559 | \\export fn bar() void { |
| 6552 | \\ _ = generic(FooType); | 6560 | \\ _ = generic(FooType); |
| 6553 | \\} | 6561 | \\} |
| 6562 | \\export fn bav() void { | ||
| 6563 | \\ _ = generic(@TypeOf(null)); | ||
| 6564 | \\} | ||
| 6565 | \\export fn baz() void { | ||
| 6566 | \\ _ = generic(@TypeOf(undefined)); | ||
| 6567 | \\} | ||
| 6554 | , &[_][]const u8{ | 6568 | , &[_][]const u8{ |
| 6555 | "tmp.zig:6:16: error: call to generic function with return type 'FooType' not allowed", | 6569 | "tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed", |
| 6556 | "tmp.zig:2:1: note: function declared here", | 6570 | "tmp.zig:2:1: note: function declared here", |
| 6557 | "tmp.zig:1:1: note: type declared here", | 6571 | "tmp.zig:1:1: note: type declared here", |
| 6572 | "tmp.zig:9:16: error: call to generic function with Null return type '(null)' not allowed", | ||
| 6573 | "tmp.zig:2:1: note: function declared here", | ||
| 6574 | "tmp.zig:12:16: error: call to generic function with Undefined return type '(undefined)' not allowed", | ||
| 6575 | "tmp.zig:2:1: note: function declared here", | ||
| 6558 | }); | 6576 | }); |
| 6559 | 6577 | ||
| 6560 | cases.add( // fixed bug #2032 | 6578 | cases.add( // fixed bug #2032 |