@@ -669,21 +669,8 @@ SubstitutionMap SubstitutionMap::mapIntoTypeExpansionContext(
669
669
SubstFlags::PreservePackExpansionLevel);
670
670
}
671
671
672
- bool OuterSubstitutions::isUnsubstitutedTypeParameter (Type type) const {
673
- if (!type->isTypeParameter ())
674
- return false ;
675
-
676
- if (auto depMemTy = type->getAs <DependentMemberType>())
677
- return isUnsubstitutedTypeParameter (depMemTy->getBase ());
678
-
679
- if (auto genericParam = type->getAs <GenericTypeParamType>())
680
- return genericParam->getDepth () >= depth;
681
-
682
- return false ;
683
- }
684
-
685
672
Type OuterSubstitutions::operator ()(SubstitutableType *type) const {
686
- if (isUnsubstitutedTypeParameter (type))
673
+ if (cast<GenericTypeParamType> (type)-> getDepth () >= depth )
687
674
return Type (type);
688
675
689
676
return QuerySubstitutionMap{subs}(type);
@@ -693,9 +680,23 @@ ProtocolConformanceRef OuterSubstitutions::operator()(
693
680
CanType dependentType,
694
681
Type conformingReplacementType,
695
682
ProtocolDecl *conformedProtocol) const {
696
- if (isUnsubstitutedTypeParameter (dependentType))
697
- return ProtocolConformanceRef::forAbstract (
683
+ auto sig = subs.getGenericSignature ();
684
+ if (!sig->isValidTypeParameter (dependentType) ||
685
+ !sig->requiresProtocol (dependentType, conformedProtocol)) {
686
+ // FIXME: We need the isValidTypeParameter() check instead of just looking
687
+ // at the root generic parameter because in the case of an existential
688
+ // environment, the reduced type of a member type of Self might be an outer
689
+ // type parameter that is not formed from the outer generic signature's
690
+ // conformance requirements. Ideally, we'd either add these supplementary
691
+ // conformance requirements to the generalization signature, or we would
692
+ // store the supplementary conformances directly in the generic environment
693
+ // somehow.
694
+ //
695
+ // Once we check for that and handle it properly, the lookupConformance()
696
+ // can become a forAbstract().
697
+ return swift::lookupConformance (
698
698
conformingReplacementType, conformedProtocol);
699
+ }
699
700
700
701
return LookUpConformanceInSubstitutionMap (subs)(
701
702
dependentType, conformingReplacementType, conformedProtocol);
0 commit comments