Skip to content

Commit 2aeb78b

Browse files
committed
[NFC] Move duplicate ObjCImpl diagnosis
1 parent 5201b3f commit 2aeb78b

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5682,21 +5682,6 @@ findImplsGivenInterface(ClassDecl *classDecl, Identifier categoryName) {
56825682
impls.push_back(ext);
56835683
}
56845684

5685-
if (impls.size() > 1) {
5686-
llvm::sort(impls, OrderDecls());
5687-
5688-
auto &diags = classDecl->getASTContext().Diags;
5689-
for (auto extraImpl : llvm::ArrayRef<Decl *>(impls).drop_front()) {
5690-
auto attr = extraImpl->getAttrs().getAttribute<ObjCImplementationAttr>();
5691-
attr->setCategoryNameInvalid();
5692-
5693-
diags.diagnose(attr->getLocation(), diag::objc_implementation_two_impls,
5694-
categoryName, classDecl)
5695-
.fixItRemove(attr->getRangeWithAt());
5696-
diags.diagnose(impls.front(), diag::previous_objc_implementation);
5697-
}
5698-
}
5699-
57005685
return impls;
57015686
}
57025687

@@ -5727,10 +5712,26 @@ findInterfaceGivenImpl(ClassDecl *classDecl, ExtensionDecl *ext) {
57275712
}
57285713

57295714
static ObjCInterfaceAndImplementation
5730-
constructResult(Decl *interface, llvm::TinyPtrVector<Decl *> impls) {
5731-
if (impls.empty())
5715+
constructResult(Decl *interface, llvm::TinyPtrVector<Decl *> &impls,
5716+
Decl *diagnoseOn, Identifier categoryName) {
5717+
if (!interface || impls.empty())
57325718
return ObjCInterfaceAndImplementation();
57335719

5720+
if (impls.size() > 1) {
5721+
llvm::sort(impls, OrderDecls());
5722+
5723+
auto &diags = interface->getASTContext().Diags;
5724+
for (auto extraImpl : llvm::ArrayRef<Decl *>(impls).drop_front()) {
5725+
auto attr = extraImpl->getAttrs().getAttribute<ObjCImplementationAttr>();
5726+
attr->setCategoryNameInvalid();
5727+
5728+
diags.diagnose(attr->getLocation(), diag::objc_implementation_two_impls,
5729+
categoryName, diagnoseOn)
5730+
.fixItRemove(attr->getRangeWithAt());
5731+
diags.diagnose(impls.front(), diag::previous_objc_implementation);
5732+
}
5733+
}
5734+
57345735
return ObjCInterfaceAndImplementation(interface, impls.front());
57355736
}
57365737

@@ -5779,7 +5780,7 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
57795780
// look for extensions implementing it.
57805781

57815782
auto implDecls = findImplsGivenInterface(classDecl, categoryName);
5782-
return constructResult(interfaceDecl, implDecls);
5783+
return constructResult(interfaceDecl, implDecls, classDecl, categoryName);
57835784
}
57845785

57855786
ObjCInterfaceAndImplementation ObjCInterfaceAndImplementationRequest::

0 commit comments

Comments
 (0)