Skip to content

Commit 1ced4b3

Browse files
committed
Check the function parameter type only for the rename to overloaded methods
1 parent 7b76115 commit 1ced4b3

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -942,43 +942,56 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
942942
SmallVector<ValueDecl *, 4> lookupResults;
943943
declContext->lookupQualified(typeDecl, renamedDeclName,
944944
NL_QualifiedDefault, lookupResults);
945-
for (auto candidate : lookupResults) {
945+
946+
if (lookupResults.size() == 1) {
947+
auto candidate = lookupResults[0];
946948
if (!shouldInclude(candidate))
947-
continue;
948-
949+
return nullptr;
949950
if (candidate->getKind() != D->getKind() ||
950951
(candidate->isInstanceMember() !=
951952
cast<ValueDecl>(D)->isInstanceMember()))
952-
continue;
953-
954-
if (isa<FuncDecl>(candidate)) {
955-
auto cParams = cast<FuncDecl>(candidate)->getParameters();
956-
auto dParams = cast<FuncDecl>(D)->getParameters();
953+
return nullptr;
957954

958-
if (cParams->size() != dParams->size())
955+
renamedDecl = candidate;
956+
} else {
957+
for (auto candidate : lookupResults) {
958+
if (!shouldInclude(candidate))
959959
continue;
960-
961-
bool hasSameParameterTypes = true;
962-
for (auto index : indices(*cParams)) {
963-
auto cParamsType = cParams->get(index)->getType();
964-
auto dParamsType = dParams->get(index)->getType();
965-
if (!cParamsType->matchesParameter(dParamsType, TypeMatchOptions())) {
966-
hasSameParameterTypes = false;
967-
break;
960+
961+
if (candidate->getKind() != D->getKind() ||
962+
(candidate->isInstanceMember() !=
963+
cast<ValueDecl>(D)->isInstanceMember()))
964+
continue;
965+
966+
if (isa<FuncDecl>(candidate)) {
967+
auto cParams = cast<FuncDecl>(candidate)->getParameters();
968+
auto dParams = cast<FuncDecl>(D)->getParameters();
969+
970+
if (cParams->size() != dParams->size())
971+
continue;
972+
973+
bool hasSameParameterTypes = true;
974+
for (auto index : indices(*cParams)) {
975+
auto cParamsType = cParams->get(index)->getType();
976+
auto dParamsType = dParams->get(index)->getType();
977+
if (!cParamsType->matchesParameter(dParamsType, TypeMatchOptions())) {
978+
hasSameParameterTypes = false;
979+
break;
980+
}
981+
}
982+
983+
if (!hasSameParameterTypes) {
984+
continue;
968985
}
969986
}
970-
971-
if (!hasSameParameterTypes) {
972-
continue;
987+
988+
if (renamedDecl) {
989+
// If we found a duplicated candidate then we would silently fail.
990+
renamedDecl = nullptr;
991+
break;
973992
}
993+
renamedDecl = candidate;
974994
}
975-
976-
if (renamedDecl) {
977-
// If we found a duplicated candidate then we would silently fail.
978-
renamedDecl = nullptr;
979-
break;
980-
}
981-
renamedDecl = candidate;
982995
}
983996
return renamedDecl;
984997
}

0 commit comments

Comments
 (0)