Skip to content

Commit e25fa23

Browse files
committed
[Sema] NFC: Cleanup lookupObjCMethodInClass
1 parent da78d93 commit e25fa23

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,19 +1920,16 @@ namespace {
19201920
} // end anonymous namespace
19211921

19221922
/// Lookup for an Objective-C method with the given selector in the
1923-
/// given class or any of its superclasses.
1924-
static AbstractFunctionDecl *lookupObjCMethodInClass(
1925-
ClassDecl *classDecl,
1926-
ObjCSelector selector,
1927-
bool isInstanceMethod,
1928-
bool isInitializer,
1929-
SourceManager &srcMgr,
1930-
bool inheritingInits = true) {
1931-
if (!classDecl)
1932-
return nullptr;
1923+
/// given class or any of its superclasses. We intentionally don't respect
1924+
/// access control, since everything is visible to the Objective-C runtime.
1925+
static AbstractFunctionDecl *
1926+
lookupOverridenObjCMethod(ClassDecl *classDecl, AbstractFunctionDecl *method,
1927+
bool inheritingInits = true) {
1928+
assert(classDecl);
19331929

19341930
// Look for an Objective-C method in this class.
1935-
auto methods = classDecl->lookupDirect(selector, isInstanceMethod);
1931+
auto methods = classDecl->lookupDirect(method->getObjCSelector(),
1932+
method->isObjCInstanceMethod());
19361933
if (!methods.empty()) {
19371934
// If we aren't inheriting initializers, remove any initializers from the
19381935
// list.
@@ -1947,19 +1944,19 @@ static AbstractFunctionDecl *lookupObjCMethodInClass(
19471944
OrderDeclarations());
19481945
}
19491946

1950-
// Recurse into the superclass.
1947+
// If we've reached the bottom of the inheritance heirarchy, we're done.
19511948
if (!classDecl->hasSuperclass())
19521949
return nullptr;
19531950

19541951
// Determine whether we are (still) inheriting initializers.
1955-
inheritingInits = inheritingInits &&
1956-
classDecl->inheritsSuperclassInitializers();
1957-
if (isInitializer && !inheritingInits)
1952+
if (!classDecl->inheritsSuperclassInitializers())
1953+
inheritingInits = false;
1954+
1955+
if (isa<ConstructorDecl>(method) && !inheritingInits)
19581956
return nullptr;
19591957

1960-
return lookupObjCMethodInClass(classDecl->getSuperclassDecl(), selector,
1961-
isInstanceMethod, isInitializer, srcMgr,
1962-
inheritingInits);
1958+
return lookupOverridenObjCMethod(classDecl->getSuperclassDecl(), method,
1959+
inheritingInits);
19631960
}
19641961

19651962
bool swift::diagnoseUnintendedObjCMethodOverrides(SourceFile &sf) {
@@ -2007,18 +2004,13 @@ bool swift::diagnoseUnintendedObjCMethodOverrides(SourceFile &sf) {
20072004
if (!classDecl->hasSuperclass())
20082005
continue;
20092006

2010-
// Look for a method that we have overridden in one of our
2011-
// superclasses.
2007+
// Look for a method that we have overridden in one of our superclasses by
2008+
// virtue of having the same selector.
20122009
// Note: This should be treated as a lookup for intra-module dependency
20132010
// purposes, but a subclass already depends on its superclasses and any
20142011
// extensions for many other reasons.
2015-
auto selector = method->getObjCSelector();
2016-
AbstractFunctionDecl *overriddenMethod
2017-
= lookupObjCMethodInClass(classDecl->getSuperclassDecl(),
2018-
selector,
2019-
method->isObjCInstanceMethod(),
2020-
isa<ConstructorDecl>(method),
2021-
Ctx.SourceMgr);
2012+
auto *overriddenMethod =
2013+
lookupOverridenObjCMethod(classDecl->getSuperclassDecl(), method);
20222014
if (!overriddenMethod)
20232015
continue;
20242016

0 commit comments

Comments
 (0)