@@ -809,33 +809,37 @@ AssociatedTypeDecl *AssociatedTypeInference::findDefaultedAssociatedType(
809809
810810Type AssociatedTypeInference::computeFixedTypeWitness (
811811 AssociatedTypeDecl *assocType) {
812+ Type resultType;
813+ auto *const structuralTy = DependentMemberType::get (
814+ proto->getSelfInterfaceType (), assocType->getName ());
815+
812816 // Look at all of the inherited protocols to determine whether they
813817 // require a fixed type for this associated type.
814- Type resultType;
815818 for (auto conformedProto : adoptee->getAnyNominal ()->getAllProtocols ()) {
816819 if (conformedProto != assocType->getProtocol () &&
817820 !conformedProto->inheritsFrom (assocType->getProtocol ()))
818821 continue ;
819822
820- const auto genericSig = conformedProto->getGenericSignature ();
821- if (!genericSig) return Type ();
823+ const auto ty =
824+ conformedProto->getGenericSignature ()->getCanonicalTypeInContext (
825+ structuralTy);
822826
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 ;
830834 }
831835
832836 if (!resultType) {
833- resultType = nestedType ;
837+ resultType = ty ;
834838 continue ;
835839 }
836840
837841 // FIXME: Bailing out on ambiguity.
838- if (!resultType->isEqual (nestedType ))
842+ if (!resultType->isEqual (ty ))
839843 return Type ();
840844 }
841845
0 commit comments