mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Factor out duplicated definition of compareAssociatedTypes()
This commit is contained in:
@@ -1979,35 +1979,6 @@ bool EquivalenceClass::isConformanceSatisfiedBySuperclass(
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Compare two associated types.
|
||||
static int compareAssociatedTypes(AssociatedTypeDecl *assocType1,
|
||||
AssociatedTypeDecl *assocType2) {
|
||||
// - by name.
|
||||
if (int result = assocType1->getName().str().compare(
|
||||
assocType2->getName().str()))
|
||||
return result;
|
||||
|
||||
// Prefer an associated type with no overrides (i.e., an anchor) to one
|
||||
// that has overrides.
|
||||
bool hasOverridden1 = !assocType1->getOverriddenDecls().empty();
|
||||
bool hasOverridden2 = !assocType2->getOverriddenDecls().empty();
|
||||
if (hasOverridden1 != hasOverridden2)
|
||||
return hasOverridden1 ? +1 : -1;
|
||||
|
||||
// - by protocol, so t_n_m.`P.T` < t_n_m.`Q.T` (given P < Q)
|
||||
auto proto1 = assocType1->getProtocol();
|
||||
auto proto2 = assocType2->getProtocol();
|
||||
if (int compareProtocols = TypeDecl::compare(proto1, proto2))
|
||||
return compareProtocols;
|
||||
|
||||
// Error case: if we have two associated types with the same name in the
|
||||
// same protocol, just tie-break based on address.
|
||||
if (assocType1 != assocType2)
|
||||
return assocType1 < assocType2 ? -1 : +1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void lookupConcreteNestedType(NominalTypeDecl *decl,
|
||||
Identifier name,
|
||||
SmallVectorImpl<TypeDecl *> &concreteDecls) {
|
||||
|
||||
Reference in New Issue
Block a user