@@ -660,39 +660,19 @@ static void recordShadowedDeclsAfterTypeMatch(
660
660
}
661
661
}
662
662
663
- // The Foundation overlay introduced Data.withUnsafeBytes, which is
664
- // treated as being ambiguous with SwiftNIO's Data.withUnsafeBytes
665
- // extension. Apply a special-case name shadowing rule to use the
666
- // latter rather than the former, which be the consequence of a more
667
- // significant change to name shadowing in the future.
668
- if (auto owningStruct1
669
- = firstDecl->getDeclContext ()->getSelfStructDecl ()) {
670
- if (auto owningStruct2
671
- = secondDecl->getDeclContext ()->getSelfStructDecl ()) {
672
- if (owningStruct1 == owningStruct2 &&
673
- owningStruct1->getName ().is (" Data" ) &&
674
- isa<FuncDecl>(firstDecl) && isa<FuncDecl>(secondDecl) &&
675
- firstDecl->getName () == secondDecl->getName () &&
676
- firstDecl->getBaseName ().userFacingName () == " withUnsafeBytes" ) {
677
- // If the second module is the Foundation module and the first
678
- // is the NIOFoundationCompat module, the second is shadowed by the
679
- // first.
680
- if (firstDecl->getModuleContext ()->getName ()
681
- .is (" NIOFoundationCompat" ) &&
682
- secondDecl->getModuleContext ()->getName ().is (" Foundation" )) {
683
- shadowed.insert (secondDecl);
684
- continue ;
685
- }
686
-
687
- // If it's the other way around, the first declaration is shadowed
688
- // by the second.
689
- if (secondDecl->getModuleContext ()->getName ()
690
- .is (" NIOFoundationCompat" ) &&
691
- firstDecl->getModuleContext ()->getName ().is (" Foundation" )) {
692
- shadowed.insert (firstDecl);
693
- break ;
694
- }
663
+ // Next, prefer any other module over the Foundation module
664
+ if (auto foundationModule = ctx.getLoadedModule (ctx.Id_Foundation )) {
665
+ if ((firstModule == foundationModule) !=
666
+ (secondModule == foundationModule)) {
667
+ // If second module is Foundation, then it is shadowed by first
668
+ if (secondModule == foundationModule) {
669
+ shadowed.insert (secondDecl);
670
+ continue ;
695
671
}
672
+
673
+ // Otherwise, the first declaration is shadowed by the second.
674
+ shadowed.insert (firstDecl);
675
+ break ;
696
676
}
697
677
}
698
678
0 commit comments