@@ -1577,23 +1577,27 @@ shouldOpenExistentialCallArgument(ValueDecl *callee, unsigned paramIdx,
1577
1577
if (genericParam->getDepth() < genericSig->getMaxDepth())
1578
1578
return std::nullopt;
1579
1579
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
+
1580
1590
// If the existential argument conforms to all of protocol requirements on
1581
1591
// the formal parameter's type, don't open unless ImplicitOpenExistentials is
1582
1592
// enabled.
1583
1593
1584
1594
// If all of the conformance requirements on the formal parameter's type
1585
1595
// are self-conforming, don't open.
1586
- ASTContext &ctx = argTy->getASTContext();
1587
1596
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;
1593
1597
bool containsNonSelfConformance = false;
1594
1598
for (auto proto : genericSig->getRequiredProtocols(genericParam)) {
1595
1599
auto conformance = lookupExistentialConformance(
1596
- existentialObjectType , proto);
1600
+ existentialTy , proto);
1597
1601
if (conformance.isInvalid()) {
1598
1602
containsNonSelfConformance = true;
1599
1603
break;
@@ -1604,10 +1608,13 @@ shouldOpenExistentialCallArgument(ValueDecl *callee, unsigned paramIdx,
1604
1608
return std::nullopt;
1605
1609
}
1606
1610
1611
+ auto existentialSig = ctx.getOpenedExistentialSignature(existentialTy);
1612
+
1607
1613
// Ensure that the formal parameter is only used in covariant positions,
1608
1614
// because it won't match anywhere else.
1609
1615
auto referenceInfo = findGenericParameterReferences(
1610
- callee, genericSig, genericParam, genericParam,
1616
+ callee, existentialSig.OpenedSig, genericParam,
1617
+ existentialSig.SelfType->castTo<GenericTypeParamType>(),
1611
1618
/*skipParamIdx=*/paramIdx);
1612
1619
if (referenceInfo.selfRef > TypePosition::Covariant ||
1613
1620
referenceInfo.assocTypeRef > TypePosition::Covariant)
0 commit comments