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
19571957
19581958 if(!is_valid_return_type(specified_return_type)){
19591959 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)));
19611961 Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name);
19621962 if (tld != nullptr) {
19631963 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,
1934219342
1934319343 if(!is_valid_return_type(specified_return_type)){
1934419344 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)));
1934619346 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));
1934719347
1934819348 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 {
65386538 \\export fn bar() !FooType {
65396539 \\ return error.InvalidValue;
65406540 \\}
6541 \\export fn bav() !@TypeOf(null) {
6542 \\ return error.InvalidValue;
6543 \\}
6544 \\export fn baz() !@TypeOf(undefined) {
6545 \\ return error.InvalidValue;
6546 \\}
65416547 , &[_][]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",
65436549 "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",
65446552 });
65456553
65466554 cases.add("generic function returning opaque type",
......@@ -6551,10 +6559,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
65516559 \\export fn bar() void {
65526560 \\ _ = generic(FooType);
65536561 \\}
6562 \\export fn bav() void {
6563 \\ _ = generic(@TypeOf(null));
6564 \\}
6565 \\export fn baz() void {
6566 \\ _ = generic(@TypeOf(undefined));
6567 \\}
65546568 , &[_][]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",
65566570 "tmp.zig:2:1: note: function declared here",
65576571 "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",
65586576 });
65596577
65606578 cases.add( // fixed bug #2032