@@ -2389,6 +2389,7 @@ Type AssociatedTypeInference::computeFixedTypeWitness(
2389
2389
// any fix this associated type to a concrete type.
2390
2390
for (auto conformance : getPeerConformances (conformance)) {
2391
2391
auto *conformedProto = conformance->getProtocol ();
2392
+
2392
2393
auto sig = conformedProto->getGenericSignature ();
2393
2394
2394
2395
// FIXME: The RequirementMachine will assert on re-entrant construction.
@@ -2704,35 +2705,40 @@ void AssociatedTypeInference::collectAbstractTypeWitnesses(
2704
2705
if (system.hasResolvedTypeWitness (assocType->getName ()))
2705
2706
continue ;
2706
2707
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 ;
2725
2709
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 ;
2731
2727
}
2732
2728
}
2733
2729
}
2734
2730
}
2735
2731
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
+ }
2736
2742
}
2737
2743
}
2738
2744
0 commit comments