better error messages and more tests
parent
7782c76bee
commit
e7cc456421
|
@ -1957,7 +1957,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
|
|||
|
||||
if(!is_valid_return_type(specified_return_type)){
|
||||
ErrorMsg* msg = add_node_error(g, fn_proto->return_type,
|
||||
buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
|
||||
buf_sprintf("%s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name)));
|
||||
Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name);
|
||||
if (tld != nullptr) {
|
||||
add_error_note(g, msg, tld->source_node, buf_sprintf("type declared here"));
|
||||
|
|
|
@ -19342,7 +19342,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
|
|||
|
||||
if(!is_valid_return_type(specified_return_type)){
|
||||
ErrorMsg *msg = ir_add_error(ira, source_instr,
|
||||
buf_sprintf("call to generic function with return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
|
||||
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)));
|
||||
add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));
|
||||
|
||||
Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name);
|
||||
|
|
|
@ -6538,9 +6538,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||
\\export fn bar() !FooType {
|
||||
\\ return error.InvalidValue;
|
||||
\\}
|
||||
\\export fn bav() !@TypeOf(null) {
|
||||
\\ return error.InvalidValue;
|
||||
\\}
|
||||
\\export fn baz() !@TypeOf(undefined) {
|
||||
\\ return error.InvalidValue;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:18: error: return type 'FooType' not allowed",
|
||||
"tmp.zig:2:18: error: Opaque return type 'FooType' not allowed",
|
||||
"tmp.zig:1:1: note: type declared here",
|
||||
"tmp.zig:5:18: error: Null return type '(null)' not allowed",
|
||||
"tmp.zig:8:18: error: Undefined return type '(undefined)' not allowed",
|
||||
});
|
||||
|
||||
cases.add("generic function returning opaque type",
|
||||
|
@ -6551,10 +6559,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
|||
\\export fn bar() void {
|
||||
\\ _ = generic(FooType);
|
||||
\\}
|
||||
\\export fn bav() void {
|
||||
\\ _ = generic(@TypeOf(null));
|
||||
\\}
|
||||
\\export fn baz() void {
|
||||
\\ _ = generic(@TypeOf(undefined));
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:6:16: error: call to generic function with return type 'FooType' not allowed",
|
||||
"tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed",
|
||||
"tmp.zig:2:1: note: function declared here",
|
||||
"tmp.zig:1:1: note: type declared here",
|
||||
"tmp.zig:9:16: error: call to generic function with Null return type '(null)' not allowed",
|
||||
"tmp.zig:2:1: note: function declared here",
|
||||
"tmp.zig:12:16: error: call to generic function with Undefined return type '(undefined)' not allowed",
|
||||
"tmp.zig:2:1: note: function declared here",
|
||||
});
|
||||
|
||||
cases.add( // fixed bug #2032
|
||||
|
|
Loading…
Reference in New Issue