authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-03-09 19:36:15+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-03-09 22:33:18+01:00
loge7cc45642138472c29e09cd10e31962426c1aba5
tree24c9aad00056e2a31e7d1509d9f4924fc77c3222
parent7782c76bee0201227be730ae131171939f728538

better error messages and more tests


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
19571957
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,
1934219342
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"));
1934719347
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 });
65456553
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 });
65596577
6560 cases.add( // fixed bug #20326578 cases.add( // fixed bug #2032