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