Skip to content

Allow extensions to define private module methods #60394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,12 +1726,17 @@ shouldDiagnoseConflict(NominalTypeDecl *ty, AbstractFunctionDecl *newDecl,
// bridging header? Some code bases implement ObjC methods in Swift even
// though it's not exactly supported.
auto newDeclModuleName = newDecl->getModuleContext()->getName();
auto newDeclPrivateModuleName = newDecl->getASTContext().getIdentifier(
(llvm::Twine(newDeclModuleName.str()) + "_Private").str());
auto bridgingHeaderModuleName = newDecl->getASTContext().getIdentifier(
CLANG_HEADER_MODULE_NAME);
if (llvm::all_of(vec, [&](AbstractFunctionDecl *oldDecl) {
if (!oldDecl->hasClangNode())
return false;
auto oldDeclModuleName = oldDecl->getModuleContext()->getName();
return oldDeclModuleName == newDeclModuleName
|| oldDeclModuleName.str() == CLANG_HEADER_MODULE_NAME;
|| oldDeclModuleName == newDeclPrivateModuleName
|| oldDeclModuleName == bridgingHeaderModuleName;
}))
return false;

Expand Down
5 changes: 0 additions & 5 deletions test/ClangImporter/Inputs/custom-modules/module.map
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,3 @@ module CommonName {
header "CommonName.h"
export *
}

module objc_init_redundant {
header "objc_init_redundant.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework module objc_init_redundant {
header "objc_init_redundant.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework module objc_init_redundant_Private {
header "objc_init_redundant_priv.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <Foundation.h>

@interface MyPrivateObject : NSObject

- (void)implementedInSwift;

@end
10 changes: 8 additions & 2 deletions test/ClangImporter/objc_init_redundant.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// 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
// 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
// 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
// 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
// RUN: %FileCheck %s < %t.log

// REQUIRES: objc_interop

import Foundation
@_implementationOnly import objc_init_redundant_Private

// rdar://problem/17687082
extension NSObject {
Expand All @@ -28,3 +29,8 @@ extension MyObject {
extension MyBridgedObject {
@objc func implementedInSwift() {}
}

// ...or the private module
extension MyPrivateObject {
@objc func implementedInSwift() {}
}