@@ -267,6 +267,42 @@ static void recordShadowedDeclsAfterSignatureMatch(
267
267
}
268
268
}
269
269
270
+ // The Foundation overlay introduced Data.withUnsafeBytes, which is
271
+ // treated as being ambiguous with SwiftNIO's Data.withUnsafeBytes
272
+ // extension. Apply a special-case name shadowing rule to use the
273
+ // latter rather than the former, which be the consequence of a more
274
+ // significant change to name shadowing in the future.
275
+ if (auto owningStruct1
276
+ = firstDecl->getDeclContext ()->getSelfStructDecl ()) {
277
+ if (auto owningStruct2
278
+ = secondDecl->getDeclContext ()->getSelfStructDecl ()) {
279
+ if (owningStruct1 == owningStruct2 &&
280
+ owningStruct1->getName ().is (" Data" ) &&
281
+ isa<FuncDecl>(firstDecl) && isa<FuncDecl>(secondDecl) &&
282
+ firstDecl->getFullName () == secondDecl->getFullName () &&
283
+ firstDecl->getBaseName ().userFacingName () == " withUnsafeBytes" ) {
284
+ // If the second module is the Foundation module and the first
285
+ // is the NIOFoundationCompat module, the second is shadowed by the
286
+ // first.
287
+ if (firstDecl->getModuleContext ()->getName ()
288
+ .is (" NIOFoundationCompat" ) &&
289
+ secondDecl->getModuleContext ()->getName ().is (" Foundation" )) {
290
+ shadowed.insert (secondDecl);
291
+ continue ;
292
+ }
293
+
294
+ // If it's the other way around, the first declaration is shadowed
295
+ // by the second.
296
+ if (secondDecl->getModuleContext ()->getName ()
297
+ .is (" NIOFoundationCompat" ) &&
298
+ firstDecl->getModuleContext ()->getName ().is (" Foundation" )) {
299
+ shadowed.insert (firstDecl);
300
+ break ;
301
+ }
302
+ }
303
+ }
304
+ }
305
+
270
306
// Prefer declarations in an overlay to similar declarations in
271
307
// the Clang module it customizes.
272
308
if (firstDecl->hasClangNode () != secondDecl->hasClangNode ()) {
0 commit comments