@@ -3888,10 +3888,19 @@ filterProtocolRequirements(
3888
3888
return Filtered;
3889
3889
}
3890
3890
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 ());
3895
3904
};
3896
3905
3897
3906
llvm::SmallDenseMap<DeclName, llvm::SmallVector<ValueDecl *, 2 >, 4 >
@@ -3907,11 +3916,11 @@ filterProtocolRequirements(
3907
3916
auto OverloadTy = Req->getOverloadSignatureType ();
3908
3917
if (OverloadTy) {
3909
3918
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)) {
3912
3920
OverloadTy = GenericFnTy.substGenericArgs (Subs);
3913
- else
3921
+ } else {
3914
3922
OverloadTy = OverloadTy.subst (Subs)->getCanonicalType ();
3923
+ }
3915
3924
}
3916
3925
if (llvm::any_of (DeclsByName[Req->getName ()], [&](ValueDecl *OtherReq) {
3917
3926
auto OtherOverloadTy = OtherReq->getOverloadSignatureType ();
0 commit comments