@@ -1920,19 +1920,16 @@ namespace {
1920
1920
} // end anonymous namespace
1921
1921
1922
1922
// / 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);
1933
1929
1934
1930
// 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 ());
1936
1933
if (!methods.empty ()) {
1937
1934
// If we aren't inheriting initializers, remove any initializers from the
1938
1935
// list.
@@ -1947,19 +1944,19 @@ static AbstractFunctionDecl *lookupObjCMethodInClass(
1947
1944
OrderDeclarations ());
1948
1945
}
1949
1946
1950
- // Recurse into the superclass .
1947
+ // If we've reached the bottom of the inheritance heirarchy, we're done .
1951
1948
if (!classDecl->hasSuperclass ())
1952
1949
return nullptr ;
1953
1950
1954
1951
// 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)
1958
1956
return nullptr ;
1959
1957
1960
- return lookupObjCMethodInClass (classDecl->getSuperclassDecl (), selector,
1961
- isInstanceMethod, isInitializer, srcMgr,
1962
- inheritingInits);
1958
+ return lookupOverridenObjCMethod (classDecl->getSuperclassDecl (), method,
1959
+ inheritingInits);
1963
1960
}
1964
1961
1965
1962
bool swift::diagnoseUnintendedObjCMethodOverrides (SourceFile &sf) {
@@ -2007,18 +2004,13 @@ bool swift::diagnoseUnintendedObjCMethodOverrides(SourceFile &sf) {
2007
2004
if (!classDecl->hasSuperclass ())
2008
2005
continue ;
2009
2006
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 .
2012
2009
// Note: This should be treated as a lookup for intra-module dependency
2013
2010
// purposes, but a subclass already depends on its superclasses and any
2014
2011
// 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);
2022
2014
if (!overriddenMethod)
2023
2015
continue ;
2024
2016
0 commit comments