@@ -402,35 +402,46 @@ static int compareDependentTypes(
402
402
if (int compareProtocols
403
403
= ProtocolType::compareProtocols (&protoa, &protob))
404
404
return compareProtocols;
405
+
406
+ // Error case: if we have two associated types with the same name in the
407
+ // same protocol, just tie-break based on address.
408
+ if (aa != ab)
409
+ return aa < ab ? -1 : +1 ;
405
410
} else {
406
411
// A resolved archetype is always ordered before an unresolved one.
407
412
return -1 ;
408
413
}
414
+ } else {
415
+ // A resolved archetype is always ordered before an unresolved one.
416
+ if (b->getResolvedAssociatedType ())
417
+ return +1 ;
409
418
}
410
419
411
- // A resolved archetype is always ordered before an unresolved one.
412
- if (b->getResolvedAssociatedType ())
413
- return +1 ;
414
-
415
420
// Make sure typealiases are properly ordered, to avoid crashers.
416
421
// FIXME: Ideally we would eliminate typealiases earlier.
417
422
if (auto *aa = a->getTypeAliasDecl ()) {
418
423
if (auto *ab = b->getTypeAliasDecl ()) {
419
424
// - by protocol, so t_n_m.`P.T` < t_n_m.`Q.T` (given P < Q)
420
- auto protoa = aa->getDeclContext ()->getAsProtocolOrProtocolExtensionContext ();
421
- auto protob = ab->getDeclContext ()->getAsProtocolOrProtocolExtensionContext ();
425
+ auto protoa =
426
+ aa->getDeclContext ()->getAsProtocolOrProtocolExtensionContext ();
427
+ auto protob =
428
+ ab->getDeclContext ()->getAsProtocolOrProtocolExtensionContext ();
429
+
422
430
if (int compareProtocols
423
431
= ProtocolType::compareProtocols (&protoa, &protob))
424
432
return compareProtocols;
425
- }
426
433
434
+ // FIXME: Arbitrarily break the result here.
435
+ if (aa != ab)
436
+ return aa < ab ? -1 : +1 ;
437
+ } else {
438
+ // A resolved archetype is always ordered before an unresolved one.
439
+ return -1 ;
440
+ }
441
+ } else if (b->getTypeAliasDecl ()) {
427
442
// A resolved archetype is always ordered before an unresolved one.
428
- return -1 ;
429
- }
430
-
431
- // A resolved archetype is always ordered before an unresolved one.
432
- if (b->getTypeAliasDecl ())
433
443
return +1 ;
444
+ }
434
445
435
446
// Along the error path where one or both of the potential archetypes was
436
447
// renamed due to typo correction,
0 commit comments