@@ -657,21 +657,8 @@ SubstitutionMap swift::substOpaqueTypesWithUnderlyingTypes(
657
657
SubstFlags::PreservePackExpansionLevel);
658
658
}
659
659
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
-
673
660
Type OuterSubstitutions::operator ()(SubstitutableType *type) const {
674
- if (isUnsubstitutedTypeParameter (type))
661
+ if (cast<GenericTypeParamType> (type)-> getDepth () >= depth )
675
662
return Type (type);
676
663
677
664
return QuerySubstitutionMap{subs}(type);
@@ -681,9 +668,23 @@ ProtocolConformanceRef OuterSubstitutions::operator()(
681
668
CanType dependentType,
682
669
Type conformingReplacementType,
683
670
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 (
686
686
conformingReplacementType, conformedProtocol);
687
+ }
687
688
688
689
return LookUpConformanceInSubstitutionMap (subs)(
689
690
dependentType, conformingReplacementType, conformedProtocol);
0 commit comments