@@ -3023,9 +3023,13 @@ namespace {
30233023 if (mayExecuteConcurrentlyWith (
30243024 localFunc.getAsDeclContext (), getDeclContext ()) ||
30253025 (explicitClosure && explicitClosure->isPassedToSendingParameter ())) {
3026- GenericSignature genericSig;
3027- if (auto afd = localFunc.getAbstractFunctionDecl ())
3028- genericSig = afd->getGenericSignature ();
3026+ auto innermostGenericDC = localFunc.getAsDeclContext ();
3027+ while (innermostGenericDC && !innermostGenericDC->isGenericContext ())
3028+ innermostGenericDC = innermostGenericDC->getParent ();
3029+
3030+ GenericSignature genericSig = innermostGenericDC
3031+ ? innermostGenericDC->getGenericSignatureOfContext ()
3032+ : GenericSignature ();
30293033
30303034 for (const auto &capturedType :
30313035 localFunc.getCaptureInfo ().getCapturedTypes ()) {
@@ -3036,8 +3040,6 @@ namespace {
30363040 ->getDepth ();
30373041 } else if (type->isTypeParameter ()) {
30383042 genericDepth = type->getRootGenericParam ()->getDepth ();
3039-
3040- type = localFunc.getAsDeclContext ()->mapTypeIntoContext (type);
30413043 } else {
30423044 continue ;
30433045 }
@@ -3048,6 +3050,9 @@ namespace {
30483050 genericDepth < genericSig.getNextDepth () - 1 )
30493051 continue ;
30503052
3053+ if (type->isTypeParameter () && innermostGenericDC)
3054+ type = innermostGenericDC->mapTypeIntoContext (type);
3055+
30513056 // Check that the metatype is sendable.
30523057 SendableCheckContext sendableContext (getDeclContext (), preconcurrency);
30533058 diagnoseNonSendableTypes (MetatypeType::get (type),
0 commit comments