@@ -437,16 +437,36 @@ getSubstitutionsForCallee(SILModule &M,
437
437
438
438
auto origSubs = AI.getSubstitutions ();
439
439
440
- // Decompose the original substitution using the derived method signature.
441
- origCalleeSig->getSubstitutionMap (origSubs, subMap);
442
-
443
- // Drop any generic parameters that come from the derived class, leaving
444
- // only generic parameters of the method itself.
445
- if (auto derivedClassSig = calleeClassDecl->getGenericSignatureOfContext ()) {
446
- for (auto depTy : derivedClassSig->getAllDependentTypes ()) {
447
- subMap.removeType (depTy->getCanonicalType ());
448
- }
440
+ // Add generic parameters from the method itself, ignoring any generic
441
+ // parameters from the derived class.
442
+ unsigned minDepth = 0 ;
443
+ if (auto derivedClassSig = calleeClassDecl->getGenericSignatureOfContext ())
444
+ minDepth = derivedClassSig->getGenericParams ().back ()->getDepth () + 1 ;
445
+
446
+ for (auto depTy : origCalleeSig->getAllDependentTypes ()) {
447
+ // Grab the next substitution.
448
+ auto sub = origSubs.front ();
449
+ origSubs = origSubs.slice (1 );
450
+
451
+ // If the dependent type doesn't contain any generic parameter with
452
+ // a depth of at least the minimum, skip this type.
453
+ auto canTy = depTy->getCanonicalType ();
454
+ auto hasInnerGenericParameter = [minDepth](Type type) -> bool {
455
+ if (auto gp = type->getAs <GenericTypeParamType>()) {
456
+ return gp->getDepth () >= minDepth;
457
+ }
458
+ return false ;
459
+ };
460
+
461
+ if (!Type (canTy.getPointer ()).findIf (hasInnerGenericParameter))
462
+ continue ;
463
+
464
+ // Otherwise, record the replacement and conformances for the mapped
465
+ // type.
466
+ subMap.addSubstitution (canTy, sub.getReplacement ());
467
+ subMap.addConformances (canTy, sub.getConformances ());
449
468
}
469
+ assert (origSubs.empty ());
450
470
}
451
471
452
472
// Add any generic substitutions for the base class.
0 commit comments