Skip to content

Commit 22facd3

Browse files
committed
AST: Use source location instead of memory address to tie break associated types
If two associated types in an (invalid) protocol have the same name, use their source location to order them instead of their memory address. This fixes a non-deterministic test failure with the requirement machine enabled.
1 parent f90b605 commit 22facd3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/Module.h"
2424
#include "swift/AST/PrettyStackTrace.h"
2525
#include "swift/AST/Types.h"
26+
#include "swift/Basic/SourceManager.h"
2627
#include "swift/Basic/STLExtras.h"
2728
#include "RequirementMachine/RequirementMachine.h"
2829
#include <functional>
@@ -1492,9 +1493,12 @@ int swift::compareAssociatedTypes(AssociatedTypeDecl *assocType1,
14921493
return compareProtocols;
14931494

14941495
// Error case: if we have two associated types with the same name in the
1495-
// same protocol, just tie-break based on address.
1496-
if (assocType1 != assocType2)
1497-
return assocType1 < assocType2 ? -1 : +1;
1496+
// same protocol, just tie-break based on source location.
1497+
if (assocType1 != assocType2) {
1498+
auto &ctx = assocType1->getASTContext();
1499+
return ctx.SourceMgr.isBeforeInBuffer(assocType1->getLoc(),
1500+
assocType2->getLoc()) ? -1 : +1;
1501+
}
14981502

14991503
return 0;
15001504
}

0 commit comments

Comments
 (0)