@@ -393,6 +393,16 @@ static ConstructorComparison compareConstructors(ConstructorDecl *ctor1,
393
393
return ConstructorComparison::Same;
394
394
}
395
395
396
+ static bool isMemberImplementation (ValueDecl *VD) {
397
+ return VD->isObjCMemberImplementation ();
398
+ }
399
+ static bool isMemberImplementation (OperatorDecl *VD) {
400
+ return false ;
401
+ }
402
+ static bool isMemberImplementation (PrecedenceGroupDecl *VD) {
403
+ return false ;
404
+ }
405
+
396
406
// / Given a set of declarations whose names and interface types have matched,
397
407
// / figure out which of these declarations have been shadowed by others.
398
408
template <typename T>
@@ -412,7 +422,8 @@ static void recordShadowedDeclsAfterTypeMatch(
412
422
for (unsigned firstIdx : indices (decls)) {
413
423
auto firstDecl = decls[firstIdx];
414
424
auto firstModule = firstDecl->getModuleContext ();
415
- bool firstTopLevel = firstDecl->getDeclContext ()->isModuleScopeContext ();
425
+ auto firstDC = firstDecl->getDeclContext ();
426
+ bool firstTopLevel = firstDC->isModuleScopeContext ();
416
427
417
428
auto name = firstDecl->getBaseName ();
418
429
@@ -454,7 +465,8 @@ static void recordShadowedDeclsAfterTypeMatch(
454
465
// Determine whether one module takes precedence over another.
455
466
auto secondDecl = decls[secondIdx];
456
467
auto secondModule = secondDecl->getModuleContext ();
457
- bool secondTopLevel = secondDecl->getDeclContext ()->isModuleScopeContext ();
468
+ auto secondDC = secondDecl->getDeclContext ();
469
+ bool secondTopLevel = secondDC->isModuleScopeContext ();
458
470
bool secondPrivate = isPrivateImport (secondModule);
459
471
460
472
// For member types, we skip most of the below rules. Instead, we allow
@@ -538,6 +550,22 @@ static void recordShadowedDeclsAfterTypeMatch(
538
550
}
539
551
}
540
552
553
+ // Member implementations are usually filtered out by access control.
554
+ // They're sometimes visible in contexts that can directly access storage,
555
+ // though, and there they should shadow the matching imported declaration.
556
+ if (firstDC != secondDC
557
+ && firstDC->getImplementedObjCContext () ==
558
+ secondDC->getImplementedObjCContext ()) {
559
+ if (isMemberImplementation (firstDecl) && secondDecl->hasClangNode ()) {
560
+ shadowed.insert (secondDecl);
561
+ continue ;
562
+ }
563
+ if (isMemberImplementation (secondDecl) && firstDecl->hasClangNode ()) {
564
+ shadowed.insert (firstDecl);
565
+ continue ;
566
+ }
567
+ }
568
+
541
569
// Swift 4 compatibility hack: Don't shadow properties defined in
542
570
// extensions of generic types with properties defined elsewhere.
543
571
// This is due to the fact that in Swift 4, we only gave custom overload
0 commit comments