146146#include " swift/AST/Types.h"
147147#include " llvm/ADT/DenseMap.h"
148148#include " llvm/ADT/SmallVector.h"
149+ #include " NameLookup.h"
149150#include " RequirementLowering.h"
150151
151152using namespace swift ;
@@ -182,30 +183,6 @@ class ConcreteContraction {
182183
183184} // end namespace
184185
185- // / Find the most canonical member type of \p decl named \p name, using the
186- // / canonical type order.
187- static TypeDecl *lookupConcreteNestedType (ModuleDecl *module ,
188- NominalTypeDecl *decl,
189- Identifier name) {
190- SmallVector<ValueDecl *, 2 > foundMembers;
191- module ->lookupQualified (
192- decl, DeclNameRef (name),
193- NL_QualifiedDefault | NL_OnlyTypes | NL_ProtocolMembers,
194- foundMembers);
195-
196- SmallVector<TypeDecl *, 2 > concreteDecls;
197- for (auto member : foundMembers)
198- concreteDecls.push_back (cast<TypeDecl>(member));
199-
200- if (concreteDecls.empty ())
201- return nullptr ;
202-
203- return *std::min_element (concreteDecls.begin (), concreteDecls.end (),
204- [](TypeDecl *type1, TypeDecl *type2) {
205- return TypeDecl::compare (type1, type2) < 0 ;
206- });
207- }
208-
209186// / A re-implementation of Type::subst() that also handles unresolved
210187// / DependentMemberTypes by performing name lookup into the base type.
211188// /
@@ -267,12 +244,12 @@ Optional<Type> ConcreteContraction::substTypeParameter(
267244 return None;
268245 }
269246
270- auto *module = decl->getParentModule ();
271-
272247 // An unresolved DependentMemberType stores an identifier. Handle this
273248 // by performing a name lookup into the base type.
274- auto *typeDecl = lookupConcreteNestedType (module , decl,
275- memberType->getName ());
249+ SmallVector<TypeDecl *> concreteDecls;
250+ lookupConcreteNestedType (decl, memberType->getName (), concreteDecls);
251+
252+ auto *typeDecl = findBestConcreteNestedType (concreteDecls);
276253 if (typeDecl == nullptr ) {
277254 // The base type doesn't contain a member type with this name, in which
278255 // case the requirement remains unsubstituted.
@@ -285,7 +262,7 @@ Optional<Type> ConcreteContraction::substTypeParameter(
285262
286263 // Substitute the base type into the member type.
287264 auto subMap = (*substBaseType)->getContextSubstitutionMap (
288- module , typeDecl->getDeclContext ());
265+ decl-> getParentModule () , typeDecl->getDeclContext ());
289266 return typeDecl->getDeclaredInterfaceType ().subst (subMap);
290267}
291268
0 commit comments