@@ -2389,6 +2389,7 @@ Type AssociatedTypeInference::computeFixedTypeWitness(
23892389 // any fix this associated type to a concrete type.
23902390 for (auto conformance : getPeerConformances (conformance)) {
23912391 auto *conformedProto = conformance->getProtocol ();
2392+
23922393 auto sig = conformedProto->getGenericSignature ();
23932394
23942395 // FIXME: The RequirementMachine will assert on re-entrant construction.
@@ -2704,35 +2705,40 @@ void AssociatedTypeInference::collectAbstractTypeWitnesses(
27042705 if (system.hasResolvedTypeWitness (assocType->getName ()))
27052706 continue ;
27062707
2707- // If we find a default type definition, feed it to the system.
2708- if (const auto &typeWitness = computeDefaultTypeWitness (assocType)) {
2709- bool preferred = (typeWitness->getDefaultedAssocType ()->getDeclContext ()
2710- == conformance->getProtocol ());
2711- system.addDefaultTypeWitness (typeWitness->getType (),
2712- typeWitness->getDefaultedAssocType (),
2713- preferred);
2714- } else {
2715- // As a last resort, look for a generic parameter that matches the name
2716- // of the associated type.
2717- if (auto genericSig = dc->getGenericSignatureOfContext ()) {
2718- // Ignore the generic parameters for AsyncIteratorProtocol.Failure and
2719- // AsyncSequence.Failure.
2720- if (!isAsyncIteratorProtocolFailure (assocType)) {
2721- for (auto *gp : genericSig.getInnermostGenericParams ()) {
2722- // Packs cannot witness associated type requirements.
2723- if (gp->isParameterPack ())
2724- continue ;
2708+ bool found = false ;
27252709
2726- if (gp->getName () == assocType->getName ()) {
2727- system.addTypeWitness (assocType->getName (),
2728- dc->mapTypeIntoContext (gp),
2729- /* preferred=*/ true );
2730- }
2710+ // Look for a generic parameter that matches the name of the
2711+ // associated type.
2712+ if (auto genericSig = dc->getGenericSignatureOfContext ()) {
2713+ // Ignore the generic parameters for AsyncIteratorProtocol.Failure and
2714+ // AsyncSequence.Failure.
2715+ if (!isAsyncIteratorProtocolFailure (assocType)) {
2716+ for (auto *gp : genericSig.getInnermostGenericParams ()) {
2717+ // Packs cannot witness associated type requirements.
2718+ if (gp->isParameterPack ())
2719+ continue ;
2720+
2721+ if (gp->getName () == assocType->getName ()) {
2722+ system.addTypeWitness (assocType->getName (),
2723+ dc->mapTypeIntoContext (gp),
2724+ /* preferred=*/ true );
2725+ found = true ;
2726+ break ;
27312727 }
27322728 }
27332729 }
27342730 }
27352731
2732+ if (!found) {
2733+ // If we find a default type definition, feed it to the system.
2734+ if (const auto &typeWitness = computeDefaultTypeWitness (assocType)) {
2735+ bool preferred = (typeWitness->getDefaultedAssocType ()->getDeclContext ()
2736+ == conformance->getProtocol ());
2737+ system.addDefaultTypeWitness (typeWitness->getType (),
2738+ typeWitness->getDefaultedAssocType (),
2739+ preferred);
2740+ }
2741+ }
27362742 }
27372743}
27382744
0 commit comments