Skip to content

Commit d9bd0d9

Browse files
committed
ClangImporter: Refactor usage of SubscriptDecl::getIndicesInterfaceType()
1 parent 9275dd6 commit d9bd0d9

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6298,6 +6298,27 @@ void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
62986298
}
62996299
}
63006300

6301+
// Note: This function ignores labels.
6302+
static bool areParameterTypesEqual(const ParameterList &params1,
6303+
const ParameterList &params2) {
6304+
if (params1.size() != params2.size())
6305+
return false;
6306+
6307+
for (unsigned i : indices(params1)) {
6308+
if (!params1[i]->getInterfaceType()->isEqual(
6309+
params2[i]->getInterfaceType())) {
6310+
return false;
6311+
}
6312+
6313+
if (params1[i]->getValueOwnership() !=
6314+
params2[i]->getValueOwnership()) {
6315+
return false;
6316+
}
6317+
}
6318+
6319+
return true;
6320+
}
6321+
63016322
void SwiftDeclConverter::recordObjCOverride(SubscriptDecl *subscript) {
63026323
// Figure out the class in which this subscript occurs.
63036324
auto classTy = subscript->getDeclContext()->getSelfClassDecl();
@@ -6314,22 +6335,14 @@ void SwiftDeclConverter::recordObjCOverride(SubscriptDecl *subscript) {
63146335
subscript->getModuleContext()->lookupQualified(
63156336
superDecl, subscript->getFullName(),
63166337
NL_QualifiedDefault | NL_KnownNoDependency, lookup);
6317-
Type unlabeledIndices;
6338+
63186339
for (auto result : lookup) {
63196340
auto parentSub = dyn_cast<SubscriptDecl>(result);
63206341
if (!parentSub)
63216342
continue;
63226343

6323-
// Compute the type of indices for our own subscript operation, lazily.
6324-
if (!unlabeledIndices) {
6325-
unlabeledIndices = subscript->getIndicesInterfaceType()
6326-
->getUnlabeledType(Impl.SwiftContext);
6327-
}
6328-
6329-
// Compute the type of indices for the subscript we found.
6330-
auto parentUnlabeledIndices = parentSub->getIndicesInterfaceType()
6331-
->getUnlabeledType(Impl.SwiftContext);
6332-
if (!unlabeledIndices->isEqual(parentUnlabeledIndices))
6344+
if (!areParameterTypesEqual(*subscript->getIndices(),
6345+
*parentSub->getIndices()))
63336346
continue;
63346347

63356348
// The index types match. This is an override, so mark it as such.

0 commit comments

Comments
 (0)