authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-10 17:04:48+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-11 17:23:06+03:00
logc0102ac1c89db1727d7c58d566376a6a79af4e98
treee9379d61c201c8e163bb53e87bcfad6089e0b824
parentf0fdaf32d3b802e9db16a0753d9ff49a8667089b

Sema: add error for resolving inferred error set of generic function

Closes #14991

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

src/Sema.zig+10
...@@ -31523,6 +31523,16 @@ fn resolveInferredErrorSet(...@@ -31523,6 +31523,16 @@ fn resolveInferredErrorSet(
31523 if (ies_func_info.return_type.tag() == .generic_poison) {31523 if (ies_func_info.return_type.tag() == .generic_poison) {
31524 assert(ies_func_info.cc == .Inline);31524 assert(ies_func_info.cc == .Inline);
31525 } else if (ies_func_info.return_type.errorUnionSet().castTag(.error_set_inferred).?.data == ies) {31525 } else if (ies_func_info.return_type.errorUnionSet().castTag(.error_set_inferred).?.data == ies) {
31526 if (ies_func_info.is_generic) {
31527 const msg = msg: {
31528 const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{});
31529 errdefer msg.destroy(sema.gpa);
31530
31531 try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(), msg, "generic function declared here", .{});
31532 break :msg msg;
31533 };
31534 return sema.failWithOwnedErrorMsg(msg);
31535 }
31526 // In this case we are dealing with the actual InferredErrorSet object that31536 // In this case we are dealing with the actual InferredErrorSet object that
31527 // corresponds to the function, not one created to track an inline/comptime call.31537 // corresponds to the function, not one created to track an inline/comptime call.
31528 try sema.ensureFuncBodyAnalyzed(ies.func);31538 try sema.ensureFuncBodyAnalyzed(ies.func);
test/cases/compile_errors/resolve_inferred_error_set_of_generic_fn.zig created+18
...@@ -0,0 +1,18 @@
1fn foo(a: anytype) !void {
2 if (a == 0) return error.A;
3 return error.B;
4}
5const Error = error{ A, B };
6export fn entry() void {
7 const info = @typeInfo(@TypeOf(foo));
8 const ret_type = info.Fn.return_type.?;
9 const error_set = @typeInfo(ret_type).ErrorUnion.error_set;
10 _ = Error || error_set;
11}
12
13// error
14// backend=stage2
15// target=native
16//
17// :10:15: error: unable to resolve inferred error set of generic function
18// :1:1: note: generic function declared here