Skip to content

Commit 7d20056

Browse files
authored
Merge pull request swiftlang#80975 from tshortli/revert-member-import-visibility-objc-overloads-in-extensions
Revert "AST: Filter out some Obj-C overrides when MemberImportVisibility is enabled."
2 parents fe79c40 + a8ce546 commit 7d20056

18 files changed

+17
-409
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,8 +2395,6 @@ static bool isAcceptableLookupResult(const DeclContext *dc, NLOptions options,
23952395
ValueDecl *decl,
23962396
bool onlyCompleteObjectInits,
23972397
bool requireImport) {
2398-
auto &ctx = dc->getASTContext();
2399-
24002398
// Filter out designated initializers, if requested.
24012399
if (onlyCompleteObjectInits) {
24022400
if (auto ctor = dyn_cast<ConstructorDecl>(decl)) {
@@ -2414,43 +2412,19 @@ static bool isAcceptableLookupResult(const DeclContext *dc, NLOptions options,
24142412
}
24152413

24162414
// Check access.
2417-
if (!(options & NL_IgnoreAccessControl) && !ctx.isAccessControlDisabled()) {
2415+
if (!(options & NL_IgnoreAccessControl) &&
2416+
!dc->getASTContext().isAccessControlDisabled()) {
24182417
bool allowUsableFromInline = options & NL_IncludeUsableFromInline;
24192418
if (!decl->isAccessibleFrom(dc, /*forConformance*/ false,
24202419
allowUsableFromInline))
24212420
return false;
24222421
}
24232422

2424-
if (requireImport) {
2425-
// Check that there is some import in the originating context that makes
2426-
// this decl visible.
2427-
if (!(options & NL_IgnoreMissingImports)) {
2428-
if (!dc->isDeclImported(decl))
2429-
return false;
2430-
}
2431-
2432-
// Unlike in Swift, Obj-C allows method overrides to be declared in
2433-
// extensions (categories), even outside of the module that defines the
2434-
// type that is being extended. When MemberImportVisibility is enabled,
2435-
// if these overrides are not filtered out they can hijack name
2436-
// lookup and cause the compiler to insist that the module that defines
2437-
// the extension be imported, contrary to developer expectations.
2438-
//
2439-
// Filter results belonging to these extensions out, even when ignoring
2440-
// missing imports, if we're in a context that requires imports to access
2441-
// member declarations.
2442-
if (decl->getOverriddenDecl()) {
2443-
if (auto *extension = dyn_cast<ExtensionDecl>(decl->getDeclContext())) {
2444-
if (auto *nominal = extension->getExtendedNominal()) {
2445-
auto extensionMod = extension->getModuleContext();
2446-
auto nominalMod = nominal->getModuleContext();
2447-
if (!extensionMod->isSameModuleLookingThroughOverlays(nominalMod) &&
2448-
!dc->isDeclImported(extension))
2449-
return false;
2450-
}
2451-
}
2452-
}
2453-
}
2423+
// Check that there is some import in the originating context that makes this
2424+
// decl visible.
2425+
if (requireImport && !(options & NL_IgnoreMissingImports))
2426+
if (!dc->isDeclImported(decl))
2427+
return false;
24542428

24552429
// Check that it has the appropriate ABI role.
24562430
if (!ABIRoleInfo(decl).matchesOptions(options))

test/NameLookup/Inputs/MemberImportVisibility/Categories_A.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
@import Foundation;
22

3-
@interface Base
4-
- (void)overriddenInOverlayForA __attribute__((deprecated("Categories_A.h")));
5-
- (void)overriddenInOverlayForB __attribute__((deprecated("Categories_A.h")));
6-
- (void)overriddenInOverlayForC __attribute__((deprecated("Categories_A.h")));
7-
- (void)overriddenInSubclassInOverlayForC __attribute__((deprecated("Categories_A.h")));
8-
@end
9-
10-
@interface X : Base
3+
@interface X
114
@end
125

136
@interface X (A)

test/NameLookup/Inputs/MemberImportVisibility/Categories_A.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
extension X {
44
public func fromOverlayForA() {}
55
@objc public func fromOverlayForAObjC() {}
6-
7-
@available(*, deprecated, message: "Categories_A.swift")
8-
public override func overriddenInOverlayForA() {}
96
}

test/NameLookup/Inputs/MemberImportVisibility/Categories_B.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
extension X {
44
public func fromOverlayForB() {}
55
@objc public func fromOverlayForBObjC() {}
6-
7-
@available(*, deprecated, message: "Categories_B.swift")
8-
public override func overriddenInOverlayForB() {}
96
}

test/NameLookup/Inputs/MemberImportVisibility/Categories_C.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@
33
@interface X (C)
44
- (void)fromC;
55
@end
6-
7-
@interface SubclassFromC : X
8-
- (instancetype)init;
9-
@end

test/NameLookup/Inputs/MemberImportVisibility/Categories_C.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,4 @@
33
extension X {
44
public func fromOverlayForC() {}
55
@objc public func fromOverlayForCObjC() {}
6-
7-
@available(*, deprecated, message: "Categories_C.swift")
8-
public override func overriddenInOverlayForC() {}
9-
}
10-
11-
extension SubclassFromC {
12-
@available(*, deprecated, message: "Categories_C.swift")
13-
public override func overriddenInSubclassInOverlayForC() {}
146
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
import Categories_C
22
import Categories_D.Submodule
3-
4-
public func makeSubclassFromC() -> SubclassFromC { SubclassFromC() }

test/NameLookup/Inputs/MemberImportVisibility/ObjCOverloads/Branch.h

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/NameLookup/Inputs/MemberImportVisibility/ObjCOverloads/Fruit.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/NameLookup/Inputs/MemberImportVisibility/ObjCOverloads/Leaf.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)