@@ -3024,9 +3024,13 @@ namespace {
30243024 if (mayExecuteConcurrentlyWith (
30253025 localFunc.getAsDeclContext (), getDeclContext ()) ||
30263026 (explicitClosure && explicitClosure->isPassedToSendingParameter ())) {
3027- GenericSignature genericSig;
3028- if (auto afd = localFunc.getAbstractFunctionDecl ())
3029- genericSig = afd->getGenericSignature ();
3027+ auto innermostGenericDC = localFunc.getAsDeclContext ();
3028+ while (innermostGenericDC && !innermostGenericDC->isGenericContext ())
3029+ innermostGenericDC = innermostGenericDC->getParent ();
3030+
3031+ GenericSignature genericSig = innermostGenericDC
3032+ ? innermostGenericDC->getGenericSignatureOfContext ()
3033+ : GenericSignature ();
30303034
30313035 for (const auto &capturedType :
30323036 localFunc.getCaptureInfo ().getCapturedTypes ()) {
@@ -3037,8 +3041,6 @@ namespace {
30373041 ->getDepth ();
30383042 } else if (type->isTypeParameter ()) {
30393043 genericDepth = type->getRootGenericParam ()->getDepth ();
3040-
3041- type = localFunc.getAsDeclContext ()->mapTypeIntoContext (type);
30423044 } else {
30433045 continue ;
30443046 }
@@ -3049,6 +3051,9 @@ namespace {
30493051 genericDepth < genericSig.getNextDepth () - 1 )
30503052 continue ;
30513053
3054+ if (type->isTypeParameter () && innermostGenericDC)
3055+ type = innermostGenericDC->mapTypeIntoContext (type);
3056+
30523057 // Check that the metatype is sendable.
30533058 SendableCheckContext sendableContext (getDeclContext (), preconcurrency);
30543059 diagnoseNonSendableTypes (MetatypeType::get (type),
0 commit comments