Skip to content

Commit 3b88a50

Browse files
committed
[NFC] Move duplicate ObjCImpl diagnosis
1 parent 98abfb4 commit 3b88a50

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
@@ -5827,21 +5827,6 @@ findImplsGivenInterface(ClassDecl *classDecl, Identifier categoryName) {
58275827
impls.push_back(ext);
58285828
}
58295829

5830-
if (impls.size() > 1) {
5831-
llvm::sort(impls, OrderDecls());
5832-
5833-
auto &diags = classDecl->getASTContext().Diags;
5834-
for (auto extraImpl : llvm::ArrayRef<Decl *>(impls).drop_front()) {
5835-
auto attr = extraImpl->getAttrs().getAttribute<ObjCImplementationAttr>();
5836-
attr->setCategoryNameInvalid();
5837-
5838-
diags.diagnose(attr->getLocation(), diag::objc_implementation_two_impls,
5839-
categoryName, classDecl)
5840-
.fixItRemove(attr->getRangeWithAt());
5841-
diags.diagnose(impls.front(), diag::previous_objc_implementation);
5842-
}
5843-
}
5844-
58455830
return impls;
58465831
}
58475832

@@ -5872,10 +5857,26 @@ findInterfaceGivenImpl(ClassDecl *classDecl, ExtensionDecl *ext) {
58725857
}
58735858

58745859
static ObjCInterfaceAndImplementation
5875-
constructResult(Decl *interface, llvm::TinyPtrVector<Decl *> impls) {
5876-
if (impls.empty())
5860+
constructResult(Decl *interface, llvm::TinyPtrVector<Decl *> &impls,
5861+
Decl *diagnoseOn, Identifier categoryName) {
5862+
if (!interface || impls.empty())
58775863
return ObjCInterfaceAndImplementation();
58785864

5865+
if (impls.size() > 1) {
5866+
llvm::sort(impls, OrderDecls());
5867+
5868+
auto &diags = interface->getASTContext().Diags;
5869+
for (auto extraImpl : llvm::ArrayRef<Decl *>(impls).drop_front()) {
5870+
auto attr = extraImpl->getAttrs().getAttribute<ObjCImplementationAttr>();
5871+
attr->setCategoryNameInvalid();
5872+
5873+
diags.diagnose(attr->getLocation(), diag::objc_implementation_two_impls,
5874+
categoryName, diagnoseOn)
5875+
.fixItRemove(attr->getRangeWithAt());
5876+
diags.diagnose(impls.front(), diag::previous_objc_implementation);
5877+
}
5878+
}
5879+
58795880
return ObjCInterfaceAndImplementation(interface, impls.front());
58805881
}
58815882

@@ -5924,7 +5925,7 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
59245925
// look for extensions implementing it.
59255926

59265927
auto implDecls = findImplsGivenInterface(classDecl, categoryName);
5927-
return constructResult(interfaceDecl, implDecls);
5928+
return constructResult(interfaceDecl, implDecls, classDecl, categoryName);
59285929
}
59295930

59305931
ObjCInterfaceAndImplementation ObjCInterfaceAndImplementationRequest::

0 commit comments

Comments
 (0)