Skip to content

Commit 4869496

Browse files
authored
Merge pull request #74572 from apple/gaborh/name-collision-tests-cherry-pick
🍒[cxx-interop] Fix inadvertently renaming static method to Mutating
2 parents 0d84a9b + 769ca57 commit 4869496

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/ClangImporter/ImportName.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
22352235
SmallString<16> newName;
22362236
// Check if we need to rename the C++ method to disambiguate it.
22372237
if (auto method = dyn_cast<clang::CXXMethodDecl>(D)) {
2238-
if (!method->isConst() && !method->isOverloadedOperator()) {
2238+
if (!method->isConst() && !method->isOverloadedOperator() && !method->isStatic()) {
22392239
// See if any other methods within the same struct have the same name, but
22402240
// differ in constness.
22412241
auto otherDecls = dc->lookup(method->getDeclName());

test/Interop/Cxx/class/method/Inputs/methods.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ struct __attribute__((swift_attr("import_unsafe"))) NonTrivialInWrapper {
1414

1515
struct HasMethods {
1616
void nonConstMethod() { }
17+
void nonConstMethod(int) { }
18+
static void nonConstMethod(float) { } // checking name colisions: rdar://120858502
1719
void constMethod() const { }
20+
static void constMethod(float) { } // checking name colisions: rdar://120858502
1821

1922
int nonConstPassThrough(int a) { return a; }
2023
int constPassThrough(int a) const { return a; }

test/Interop/Cxx/class/method/methods.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ CxxMethodTestSuite.test("() -> Void") {
1111
var instance = HasMethods()
1212

1313
instance.nonConstMethod()
14+
instance.nonConstMethod(5)
15+
HasMethods.nonConstMethod(4.2) // Testing name collision
1416
instance.constMethod()
17+
HasMethods.constMethod(4.2) // Testing name collision
1518
}
1619

1720
CxxMethodTestSuite.test("(Int) -> Int") {

0 commit comments

Comments
 (0)