@@ -716,7 +716,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
716
716
if (!nominal) continue ;
717
717
718
718
// Dig out the type we're looking into.
719
- SmallVector<NominalTypeDecl *, 2 > lookupDecls;
719
+ SmallVector<TypeDecl *, 2 > lookupDecls;
720
720
lookupDecls.push_back (nominal);
721
721
722
722
// For a protocol extension, check whether there are additional
@@ -793,7 +793,7 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
793
793
GenericParamList *GenericParams = nullptr ;
794
794
795
795
// Dig out the type we're looking into.
796
- SmallVector<NominalTypeDecl *, 2 > lookupDecls;
796
+ SmallVector<TypeDecl *, 2 > lookupDecls;
797
797
798
798
// Local function to populate the set of lookup declarations from
799
799
// the given DeclContext.
@@ -1824,10 +1824,15 @@ bool DeclContext::lookupQualified(Type type,
1824
1824
SmallVector<NominalTypeDecl *, 4 > nominalTypesToLookInto;
1825
1825
extractDirectlyReferencedNominalTypes (type, nominalTypesToLookInto);
1826
1826
1827
- return lookupQualified (nominalTypesToLookInto, member, options, decls);
1827
+ SmallVector<TypeDecl *, 4 > typeDeclsToLookInto;
1828
+ typeDeclsToLookInto.reserve (nominalTypesToLookInto.size ());
1829
+ for (auto nominal : nominalTypesToLookInto)
1830
+ typeDeclsToLookInto.push_back (nominal);
1831
+
1832
+ return lookupQualified (typeDeclsToLookInto, member, options, decls);
1828
1833
}
1829
1834
1830
- bool DeclContext::lookupQualified (ArrayRef<NominalTypeDecl *> typeDecls,
1835
+ bool DeclContext::lookupQualified (ArrayRef<TypeDecl *> typeDecls,
1831
1836
DeclName member,
1832
1837
NLOptions options,
1833
1838
SmallVectorImpl<ValueDecl *> &decls) const {
@@ -1856,12 +1861,33 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
1856
1861
return true ;
1857
1862
};
1858
1863
1859
- // Look through the type declarations we were given, resolving
1864
+ // Look through the type declarations we were given, resolving them down
1865
+ // to nominal type declarations, module declarations, and
1860
1866
ASTContext &ctx = getASTContext ();
1861
- for (auto nominal : typeDecls) {
1867
+ SmallVector<ModuleDecl *, 2 > moduleDecls;
1868
+ bool anyObject = false ;
1869
+ auto nominalTypeDecls =
1870
+ resolveTypeDeclsToNominal (ctx.evaluator , ctx, typeDecls, moduleDecls,
1871
+ anyObject);
1872
+
1873
+ // If the only declaration we were given was AnyObject, this is AnyObject
1874
+ // lookup.
1875
+ if (anyObject && nominalTypeDecls.empty () && moduleDecls.empty ())
1876
+ return lookupAnyObject (member, options, decls);
1877
+
1878
+ // Add all of the nominal types to the stack.
1879
+ for (auto nominal : nominalTypeDecls) {
1862
1880
addNominalType (nominal);
1863
1881
}
1864
1882
1883
+ // Search all of the modules.
1884
+ for (auto module : moduleDecls) {
1885
+ auto innerOptions = options;
1886
+ innerOptions &= ~NL_RemoveOverridden;
1887
+ innerOptions &= ~NL_RemoveNonVisible;
1888
+ lookupQualified (module , member, innerOptions, decls);
1889
+ }
1890
+
1865
1891
// Whether we only want to return complete object initializers.
1866
1892
bool onlyCompleteObjectInits = false ;
1867
1893
@@ -1960,7 +1986,6 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
1960
1986
NLOptions options,
1961
1987
SmallVectorImpl<ValueDecl *> &decls) const {
1962
1988
using namespace namelookup ;
1963
- assert (decls.empty () && " additive lookup not supported" );
1964
1989
1965
1990
// Configure lookup and dig out the tracker.
1966
1991
ReferencedNameTracker *tracker = nullptr ;
@@ -2185,14 +2210,6 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
2185
2210
ArrayRef<TypeDecl *> baseTypes,
2186
2211
DeclName name,
2187
2212
DeclContext *dc) {
2188
- // Look through the base types to find something on which we can perform
2189
- // qualified name lookup.
2190
- SmallVector<ModuleDecl *, 2 > moduleBaseTypes;
2191
- bool anyObject = false ;
2192
- auto nominalBaseTypes =
2193
- resolveTypeDeclsToNominal (evaluator, ctx, baseTypes, moduleBaseTypes,
2194
- anyObject);
2195
-
2196
2213
DirectlyReferencedTypeDecls result;
2197
2214
auto addResults = [&result](ArrayRef<ValueDecl *> found){
2198
2215
for (auto decl : found){
@@ -2203,21 +2220,11 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
2203
2220
};
2204
2221
2205
2222
{
2206
- // Look through nominal types.
2207
- SmallVector<ValueDecl *, 4 > nominalMembers;
2208
- auto options = NL_RemoveNonVisible | NL_OnlyTypes;
2209
- dc->lookupQualified (nominalBaseTypes, name, options, nominalMembers);
2210
- addResults (nominalMembers);
2211
- }
2212
-
2213
- {
2214
- // Look through modules.
2223
+ // Look into the base types.
2224
+ SmallVector<ValueDecl *, 4 > members;
2215
2225
auto options = NL_RemoveNonVisible | NL_OnlyTypes;
2216
- for (auto module : moduleBaseTypes) {
2217
- SmallVector<ValueDecl *, 4 > moduleMembers;
2218
- dc->lookupQualified (module , name, options, moduleMembers);
2219
- addResults (moduleMembers);
2220
- }
2226
+ dc->lookupQualified (baseTypes, name, options, members);
2227
+ addResults (members);
2221
2228
}
2222
2229
2223
2230
return result;
0 commit comments