Skip to content

🍒[cxx-interop] Fix inadvertently renaming static method to Mutating #74572

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
Jun 21, 2024
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
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
SmallString<16> newName;
// Check if we need to rename the C++ method to disambiguate it.
if (auto method = dyn_cast<clang::CXXMethodDecl>(D)) {
if (!method->isConst() && !method->isOverloadedOperator()) {
if (!method->isConst() && !method->isOverloadedOperator() && !method->isStatic()) {
// See if any other methods within the same struct have the same name, but
// differ in constness.
auto otherDecls = dc->lookup(method->getDeclName());
Expand Down
3 changes: 3 additions & 0 deletions test/Interop/Cxx/class/method/Inputs/methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ struct __attribute__((swift_attr("import_unsafe"))) NonTrivialInWrapper {

struct HasMethods {
void nonConstMethod() { }
void nonConstMethod(int) { }
static void nonConstMethod(float) { } // checking name colisions: rdar://120858502
void constMethod() const { }
static void constMethod(float) { } // checking name colisions: rdar://120858502

int nonConstPassThrough(int a) { return a; }
int constPassThrough(int a) const { return a; }
Expand Down
3 changes: 3 additions & 0 deletions test/Interop/Cxx/class/method/methods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ CxxMethodTestSuite.test("() -> Void") {
var instance = HasMethods()

instance.nonConstMethod()
instance.nonConstMethod(5)
HasMethods.nonConstMethod(4.2) // Testing name collision
instance.constMethod()
HasMethods.constMethod(4.2) // Testing name collision
}

CxxMethodTestSuite.test("(Int) -> Int") {
Expand Down