@@ -809,33 +809,37 @@ AssociatedTypeDecl *AssociatedTypeInference::findDefaultedAssociatedType(
809
809
810
810
Type AssociatedTypeInference::computeFixedTypeWitness (
811
811
AssociatedTypeDecl *assocType) {
812
+ Type resultType;
813
+ auto *const structuralTy = DependentMemberType::get (
814
+ proto->getSelfInterfaceType (), assocType->getName ());
815
+
812
816
// Look at all of the inherited protocols to determine whether they
813
817
// require a fixed type for this associated type.
814
- Type resultType;
815
818
for (auto conformedProto : adoptee->getAnyNominal ()->getAllProtocols ()) {
816
819
if (conformedProto != assocType->getProtocol () &&
817
820
!conformedProto->inheritsFrom (assocType->getProtocol ()))
818
821
continue ;
819
822
820
- const auto genericSig = conformedProto->getGenericSignature ();
821
- if (!genericSig) return Type ();
823
+ const auto ty =
824
+ conformedProto->getGenericSignature ()->getCanonicalTypeInContext (
825
+ structuralTy);
822
826
823
- const auto nestedType = genericSig-> getCanonicalTypeInContext (
824
- DependentMemberType::get (conformedProto-> getSelfInterfaceType (),
825
- assocType-> getName ()));
826
- if (nestedType-> isEqual (conformedProto-> getSelfInterfaceType () )) {
827
- // Self is a valid fixed type witness.
828
- } else if (nestedType-> isTypeParameter ()) {
829
- continue ;
827
+ // A dependent member type with an identical base and name indicates that
828
+ // the protocol does not same-type constrain it in any way; move on to
829
+ // the next protocol.
830
+ if (auto * const memberTy = ty-> getAs <DependentMemberType>( )) {
831
+ if (memberTy-> getBase ()-> isEqual (structuralTy-> getBase ()) &&
832
+ memberTy-> getName () == structuralTy-> getName ())
833
+ continue ;
830
834
}
831
835
832
836
if (!resultType) {
833
- resultType = nestedType ;
837
+ resultType = ty ;
834
838
continue ;
835
839
}
836
840
837
841
// FIXME: Bailing out on ambiguity.
838
- if (!resultType->isEqual (nestedType ))
842
+ if (!resultType->isEqual (ty ))
839
843
return Type ();
840
844
}
841
845
0 commit comments