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

Closes #14991
This commit is contained in:
Veikka Tuominen
2023-05-10 17:04:48 +03:00
parent f0fdaf32d3
commit c0102ac1c8
2 changed files with 28 additions and 0 deletions

View File

@@ -31523,6 +31523,16 @@ fn resolveInferredErrorSet(
if (ies_func_info.return_type.tag() == .generic_poison) {
assert(ies_func_info.cc == .Inline);
} else if (ies_func_info.return_type.errorUnionSet().castTag(.error_set_inferred).?.data == ies) {
if (ies_func_info.is_generic) {
const msg = msg: {
const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{});
errdefer msg.destroy(sema.gpa);
try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(), msg, "generic function declared here", .{});
break :msg msg;
};
return sema.failWithOwnedErrorMsg(msg);
}
// In this case we are dealing with the actual InferredErrorSet object that
// corresponds to the function, not one created to track an inline/comptime call.
try sema.ensureFuncBodyAnalyzed(ies.func);

View File

@@ -0,0 +1,18 @@
fn foo(a: anytype) !void {
if (a == 0) return error.A;
return error.B;
}
const Error = error{ A, B };
export fn entry() void {
const info = @typeInfo(@TypeOf(foo));
const ret_type = info.Fn.return_type.?;
const error_set = @typeInfo(ret_type).ErrorUnion.error_set;
_ = Error || error_set;
}
// error
// backend=stage2
// target=native
//
// :10:15: error: unable to resolve inferred error set of generic function
// :1:1: note: generic function declared here