Fix crash involving captured-type checking for sendable metatypes

(cherry picked from commit e4f1b62c57)
This commit is contained in:
Doug Gregor
2025-04-10 07:44:38 -07:00
parent 3ccaffd07c
commit 65a7b189ba

View File

@@ -3024,9 +3024,13 @@ namespace {
if (mayExecuteConcurrentlyWith(
localFunc.getAsDeclContext(), getDeclContext()) ||
(explicitClosure && explicitClosure->isPassedToSendingParameter())) {
GenericSignature genericSig;
if (auto afd = localFunc.getAbstractFunctionDecl())
genericSig = afd->getGenericSignature();
auto innermostGenericDC = localFunc.getAsDeclContext();
while (innermostGenericDC && !innermostGenericDC->isGenericContext())
innermostGenericDC = innermostGenericDC->getParent();
GenericSignature genericSig = innermostGenericDC
? innermostGenericDC->getGenericSignatureOfContext()
: GenericSignature();
for (const auto &capturedType :
localFunc.getCaptureInfo().getCapturedTypes()) {
@@ -3037,8 +3041,6 @@ namespace {
->getDepth();
} else if (type->isTypeParameter()) {
genericDepth = type->getRootGenericParam()->getDepth();
type = localFunc.getAsDeclContext()->mapTypeIntoContext(type);
} else {
continue;
}
@@ -3049,6 +3051,9 @@ namespace {
genericDepth < genericSig.getNextDepth() - 1)
continue;
if (type->isTypeParameter() && innermostGenericDC)
type = innermostGenericDC->mapTypeIntoContext(type);
// Check that the metatype is sendable.
SendableCheckContext sendableContext(getDeclContext(), preconcurrency);
diagnoseNonSendableTypes(MetatypeType::get(type),