@@ -1577,23 +1577,27 @@ shouldOpenExistentialCallArgument(ValueDecl *callee, unsigned paramIdx,
15771577 if (genericParam->getDepth() < genericSig->getMaxDepth())
15781578 return std::nullopt;
15791579
1580+ Type existentialTy;
1581+ if (auto existentialMetaTy = argTy->getAs<ExistentialMetatypeType>())
1582+ existentialTy = existentialMetaTy->getInstanceType();
1583+ else
1584+ existentialTy = argTy;
1585+
1586+ ASSERT(existentialTy->isExistentialType());
1587+
1588+ auto &ctx = cs.getASTContext();
1589+
15801590 // If the existential argument conforms to all of protocol requirements on
15811591 // the formal parameter's type, don't open unless ImplicitOpenExistentials is
15821592 // enabled.
15831593
15841594 // If all of the conformance requirements on the formal parameter's type
15851595 // are self-conforming, don't open.
1586- ASTContext &ctx = argTy->getASTContext();
15871596 if (!ctx.LangOpts.hasFeature(Feature::ImplicitOpenExistentials)) {
1588- Type existentialObjectType;
1589- if (auto existentialMetaTy = argTy->getAs<ExistentialMetatypeType>())
1590- existentialObjectType = existentialMetaTy->getInstanceType();
1591- else
1592- existentialObjectType = argTy;
15931597 bool containsNonSelfConformance = false;
15941598 for (auto proto : genericSig->getRequiredProtocols(genericParam)) {
15951599 auto conformance = lookupExistentialConformance(
1596- existentialObjectType , proto);
1600+ existentialTy , proto);
15971601 if (conformance.isInvalid()) {
15981602 containsNonSelfConformance = true;
15991603 break;
@@ -1604,10 +1608,13 @@ shouldOpenExistentialCallArgument(ValueDecl *callee, unsigned paramIdx,
16041608 return std::nullopt;
16051609 }
16061610
1611+ auto existentialSig = ctx.getOpenedExistentialSignature(existentialTy);
1612+
16071613 // Ensure that the formal parameter is only used in covariant positions,
16081614 // because it won't match anywhere else.
16091615 auto referenceInfo = findGenericParameterReferences(
1610- callee, genericSig, genericParam, genericParam,
1616+ callee, existentialSig.OpenedSig, genericParam,
1617+ existentialSig.SelfType->castTo<GenericTypeParamType>(),
16111618 /*skipParamIdx=*/paramIdx);
16121619 if (referenceInfo.selfRef > TypePosition::Covariant ||
16131620 referenceInfo.assocTypeRef > TypePosition::Covariant)
0 commit comments