@@ -657,21 +657,8 @@ SubstitutionMap swift::substOpaqueTypesWithUnderlyingTypes(
657657 SubstFlags::PreservePackExpansionLevel);
658658}
659659
660- bool OuterSubstitutions::isUnsubstitutedTypeParameter (Type type) const {
661- if (!type->isTypeParameter ())
662- return false ;
663-
664- if (auto depMemTy = type->getAs <DependentMemberType>())
665- return isUnsubstitutedTypeParameter (depMemTy->getBase ());
666-
667- if (auto genericParam = type->getAs <GenericTypeParamType>())
668- return genericParam->getDepth () >= depth;
669-
670- return false ;
671- }
672-
673660Type OuterSubstitutions::operator ()(SubstitutableType *type) const {
674- if (isUnsubstitutedTypeParameter (type))
661+ if (cast<GenericTypeParamType> (type)-> getDepth () >= depth )
675662 return Type (type);
676663
677664 return QuerySubstitutionMap{subs}(type);
@@ -681,9 +668,23 @@ ProtocolConformanceRef OuterSubstitutions::operator()(
681668 CanType dependentType,
682669 Type conformingReplacementType,
683670 ProtocolDecl *conformedProtocol) const {
684- if (isUnsubstitutedTypeParameter (dependentType))
685- return ProtocolConformanceRef::forAbstract (
671+ auto sig = subs.getGenericSignature ();
672+ if (!sig->isValidTypeParameter (dependentType) ||
673+ !sig->requiresProtocol (dependentType, conformedProtocol)) {
674+ // FIXME: We need the isValidTypeParameter() check instead of just looking
675+ // at the root generic parameter because in the case of an existential
676+ // environment, the reduced type of a member type of Self might be an outer
677+ // type parameter that is not formed from the outer generic signature's
678+ // conformance requirements. Ideally, we'd either add these supplementary
679+ // conformance requirements to the generalization signature, or we would
680+ // store the supplementary conformances directly in the generic environment
681+ // somehow.
682+ //
683+ // Once we check for that and handle it properly, the lookupConformance()
684+ // can become a forAbstract().
685+ return swift::lookupConformance (
686686 conformingReplacementType, conformedProtocol);
687+ }
687688
688689 return LookUpConformanceInSubstitutionMap (subs)(
689690 dependentType, conformingReplacementType, conformedProtocol);
0 commit comments