@@ -3888,10 +3888,19 @@ filterProtocolRequirements(
38883888 return Filtered;
38893889 }
38903890
3891- const auto getProtocolSubstitutionMap = [&](ValueDecl *Req) {
3892- auto *const PD = cast<ProtocolDecl>(Req->getDeclContext ());
3893- auto Conformance = lookupConformance (Adoptee, PD);
3894- return SubstitutionMap::getProtocolSubstitutions (Conformance);
3891+ const auto getProtocolSubstitutionMap = [&](ValueDecl *req) {
3892+ ASSERT (isa<ProtocolDecl>(req->getDeclContext ()));
3893+ auto genericSig = req->getInnermostDeclContext ()
3894+ ->getGenericSignatureOfContext ();
3895+ SmallVector<Type, 2 > args;
3896+ for (auto paramTy : genericSig.getGenericParams ()) {
3897+ if (args.empty ())
3898+ args.push_back (Adoptee);
3899+ else
3900+ args.push_back (paramTy);
3901+ }
3902+ return SubstitutionMap::get (genericSig, args,
3903+ LookUpConformanceInModule ());
38953904 };
38963905
38973906 llvm::SmallDenseMap<DeclName, llvm::SmallVector<ValueDecl *, 2 >, 4 >
@@ -3907,11 +3916,11 @@ filterProtocolRequirements(
39073916 auto OverloadTy = Req->getOverloadSignatureType ();
39083917 if (OverloadTy) {
39093918 auto Subs = getProtocolSubstitutionMap (Req);
3910- // FIXME: This is wrong if the overload has its own generic parameters
3911- if (auto GenericFnTy = dyn_cast<GenericFunctionType>(OverloadTy))
3919+ if (auto GenericFnTy = dyn_cast<GenericFunctionType>(OverloadTy)) {
39123920 OverloadTy = GenericFnTy.substGenericArgs (Subs);
3913- else
3921+ } else {
39143922 OverloadTy = OverloadTy.subst (Subs)->getCanonicalType ();
3923+ }
39153924 }
39163925 if (llvm::any_of (DeclsByName[Req->getName ()], [&](ValueDecl *OtherReq) {
39173926 auto OtherOverloadTy = OtherReq->getOverloadSignatureType ();
0 commit comments