@@ -2174,6 +2174,13 @@ namespace {
2174
2174
return getVersion () == getActiveSwiftVersion ();
2175
2175
}
2176
2176
2177
+ template <typename T>
2178
+ T *recordMemberInContext (DeclContext *dc, T *member) {
2179
+ assert (member && " Attempted to record null member!" );
2180
+ Impl.MembersForNominal [dc->getSelfNominalTypeDecl ()].push_back (member);
2181
+ return member;
2182
+ }
2183
+
2177
2184
// / Import the name of the given entity.
2178
2185
// /
2179
2186
// / This version of importFullName introduces any context-specific
@@ -3734,7 +3741,7 @@ namespace {
3734
3741
if (correctSwiftName)
3735
3742
markAsVariant (result, *correctSwiftName);
3736
3743
3737
- return result;
3744
+ return recordMemberInContext (dc, result) ;
3738
3745
}
3739
3746
3740
3747
void finishFuncDecl (const clang::FunctionDecl *decl,
@@ -4344,7 +4351,7 @@ namespace {
4344
4351
}
4345
4352
}
4346
4353
4347
- return result;
4354
+ return recordMemberInContext (dc, result) ;
4348
4355
}
4349
4356
4350
4357
public:
@@ -5002,44 +5009,57 @@ namespace {
5002
5009
return nullptr ;
5003
5010
5004
5011
VarDecl *overridden = nullptr ;
5005
- if (dc-> getSelfClassDecl ()) {
5006
- // Check whether there is a function with the same name as this
5007
- // property. If so, suppress the property; the user will have to use
5008
- // the methods directly, to avoid ambiguities.
5009
- NominalTypeDecl *lookupContext = dc-> getSelfNominalTypeDecl () ;
5012
+ // Check whether there is a function with the same name as this
5013
+ // property. If so, suppress the property; the user will have to use
5014
+ // the methods directly, to avoid ambiguities.
5015
+ if ( auto *subject = dc-> getSelfClassDecl ()) {
5016
+ bool foundMethod = false ;
5010
5017
5011
5018
if (auto *classDecl = dyn_cast<ClassDecl>(dc)) {
5012
5019
// If we're importing into the primary @interface for something, as
5013
5020
// opposed to an extension, make sure we don't try to load any
5014
5021
// categories...by just looking into the super type.
5015
- lookupContext = classDecl->getSuperclassDecl ();
5022
+ subject = classDecl->getSuperclassDecl ();
5016
5023
}
5024
+
5025
+ for (; subject; (subject = subject->getSuperclassDecl ())) {
5026
+ llvm::SmallVector<ValueDecl *, 8 > lookup;
5027
+ auto found = Impl.MembersForNominal .find (subject);
5028
+ if (found != Impl.MembersForNominal .end ()) {
5029
+ lookup.append (found->second .begin (), found->second .end ());
5030
+ namelookup::pruneLookupResultSet (dc, NL_QualifiedDefault, lookup);
5031
+ }
5032
+
5033
+ for (auto &result : lookup) {
5034
+ // Skip declarations that don't match the name we're looking for.
5035
+ if (result->getBaseName () != name)
5036
+ continue ;
5037
+
5038
+ if (auto *fd = dyn_cast<FuncDecl>(result)) {
5039
+ if (fd->isInstanceMember () != decl->isInstanceProperty ())
5040
+ continue ;
5041
+
5042
+ if (fd->getFullName ().getArgumentNames ().empty ()) {
5043
+ foundMethod = true ;
5044
+ }
5045
+ } else {
5046
+ auto *var = cast<VarDecl>(result);
5047
+ if (var->isInstanceMember () != decl->isInstanceProperty ())
5048
+ continue ;
5017
5049
5018
- if (lookupContext) {
5019
- SmallVector<ValueDecl *, 2 > lookup;
5020
- dc->lookupQualified (lookupContext, DeclNameRef (name),
5021
- NL_QualifiedDefault | NL_KnownNoDependency,
5022
- lookup);
5023
- bool foundMethod = false ;
5024
- for (auto result : lookup) {
5025
- if (isa<FuncDecl>(result) &&
5026
- result->isInstanceMember () == decl->isInstanceProperty () &&
5027
- result->getFullName ().getArgumentNames ().empty ())
5028
- foundMethod = true ;
5029
-
5030
- if (auto var = dyn_cast<VarDecl>(result)) {
5031
5050
// If the selectors of the getter match in Objective-C, we have an
5032
5051
// override.
5033
- if (var->isInstanceMember () == decl->isInstanceProperty () &&
5034
- var->getObjCGetterSelector () ==
5035
- Impl.importSelector (decl->getGetterName ()))
5052
+ if (var->getObjCGetterSelector () ==
5053
+ Impl.importSelector (decl->getGetterName ())) {
5036
5054
overridden = var;
5055
+ }
5037
5056
}
5038
5057
}
5039
- if (foundMethod && !overridden)
5040
- return nullptr ;
5041
5058
}
5042
5059
5060
+ if (foundMethod && !overridden)
5061
+ return nullptr ;
5062
+
5043
5063
if (overridden) {
5044
5064
const DeclContext *overrideContext = overridden->getDeclContext ();
5045
5065
// It's okay to compare interface types directly because Objective-C
@@ -5130,7 +5150,7 @@ namespace {
5130
5150
if (correctSwiftName)
5131
5151
markAsVariant (result, *correctSwiftName);
5132
5152
5133
- return result;
5153
+ return recordMemberInContext (dc, result) ;
5134
5154
}
5135
5155
5136
5156
Decl *
0 commit comments