[SILGen] Correctly determine the thrown error type for closures

When a closure throws a generic error type, we were retrieving the
substituted error type (involving archetypes) when we needed to be
working with the interface type.

Fixes rdar://124484012.
This commit is contained in:
Doug Gregor
2024-03-13 12:51:48 -07:00
parent 1cd7a56ea6
commit f54782eab5
4 changed files with 33 additions and 13 deletions

View File

@@ -1340,7 +1340,6 @@ AbstractionPattern::getFunctionThrownErrorType(
if (!optOrigErrorType)
return std::nullopt;
auto &ctx = substFnInterfaceType->getASTContext();
auto substErrorType = substFnInterfaceType->getEffectiveThrownErrorType();
if (isTypeParameterOrOpaqueArchetype()) {
@@ -1352,16 +1351,21 @@ AbstractionPattern::getFunctionThrownErrorType(
}
if (!substErrorType) {
if (optOrigErrorType->getType()->hasTypeParameter())
substErrorType = ctx.getNeverType();
else
substErrorType = optOrigErrorType->getType();
substErrorType = optOrigErrorType->getEffectiveThrownErrorType();
}
return std::make_pair(*optOrigErrorType,
(*substErrorType)->getCanonicalType());
}
CanType AbstractionPattern::getEffectiveThrownErrorType() const {
CanType type = getType();
if (type->hasTypeParameter())
return type->getASTContext().getNeverType()->getCanonicalType();
return type;
}
AbstractionPattern
AbstractionPattern::getObjCMethodAsyncCompletionHandlerType(
CanType swiftCompletionHandlerType) const {