Skip to content

Commit 68c5293

Browse files
authored
Merge pull request #60394 from beccadax/private-defective
Allow extensions to define private module methods
2 parents 103c5a4 + 600ced1 commit 68c5293

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

lib/AST/NameLookup.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,12 +1727,17 @@ shouldDiagnoseConflict(NominalTypeDecl *ty, AbstractFunctionDecl *newDecl,
17271727
// bridging header? Some code bases implement ObjC methods in Swift even
17281728
// though it's not exactly supported.
17291729
auto newDeclModuleName = newDecl->getModuleContext()->getName();
1730+
auto newDeclPrivateModuleName = newDecl->getASTContext().getIdentifier(
1731+
(llvm::Twine(newDeclModuleName.str()) + "_Private").str());
1732+
auto bridgingHeaderModuleName = newDecl->getASTContext().getIdentifier(
1733+
CLANG_HEADER_MODULE_NAME);
17301734
if (llvm::all_of(vec, [&](AbstractFunctionDecl *oldDecl) {
17311735
if (!oldDecl->hasClangNode())
17321736
return false;
17331737
auto oldDeclModuleName = oldDecl->getModuleContext()->getName();
17341738
return oldDeclModuleName == newDeclModuleName
1735-
|| oldDeclModuleName.str() == CLANG_HEADER_MODULE_NAME;
1739+
|| oldDeclModuleName == newDeclPrivateModuleName
1740+
|| oldDeclModuleName == bridgingHeaderModuleName;
17361741
}))
17371742
return false;
17381743

test/ClangImporter/Inputs/custom-modules/module.map

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,3 @@ module CommonName {
271271
header "CommonName.h"
272272
export *
273273
}
274-
275-
module objc_init_redundant {
276-
header "objc_init_redundant.h"
277-
export *
278-
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module objc_init_redundant {
2+
header "objc_init_redundant.h"
3+
export *
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module objc_init_redundant_Private {
2+
header "objc_init_redundant_priv.h"
3+
export *
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <Foundation.h>
2+
3+
@interface MyPrivateObject : NSObject
4+
5+
- (void)implementedInSwift;
6+
7+
@end

test/ClangImporter/objc_init_redundant.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk -I %S/Inputs/custom-modules) -import-underlying-module -import-objc-header %S/Inputs/objc_init_redundant_bridging.h -emit-sil %s -verify
2-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk -I %S/Inputs/custom-modules) -import-underlying-module -import-objc-header %S/Inputs/objc_init_redundant_bridging.h -emit-sil %s > %t.log 2>&1
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk -I %S/Inputs/custom-modules -F %S/Inputs/frameworks) -import-underlying-module -import-objc-header %S/Inputs/objc_init_redundant_bridging.h -emit-sil %s -verify
2+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk -I %S/Inputs/custom-modules -F %S/Inputs/frameworks) -import-underlying-module -import-objc-header %S/Inputs/objc_init_redundant_bridging.h -emit-sil %s > %t.log 2>&1
33
// RUN: %FileCheck %s < %t.log
44

55
// REQUIRES: objc_interop
66

77
import Foundation
8+
@_implementationOnly import objc_init_redundant_Private
89

910
// rdar://problem/17687082
1011
extension NSObject {
@@ -28,3 +29,8 @@ extension MyObject {
2829
extension MyBridgedObject {
2930
@objc func implementedInSwift() {}
3031
}
32+
33+
// ...or the private module
34+
extension MyPrivateObject {
35+
@objc func implementedInSwift() {}
36+
}

0 commit comments

Comments
 (0)