@@ -539,14 +539,35 @@ SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass,
539
539
if (auto derivedClassSig = derivedClass->getGenericSignature ())
540
540
origDepth = derivedClassSig.getGenericParams ().back ()->getDepth () + 1 ;
541
541
542
- SubstitutionMap origSubMap;
543
- if (derivedSig)
544
- origSubMap = derivedSig->getIdentitySubstitutionMap ();
545
-
546
- return combineSubstitutionMaps (baseSubMap, origSubMap,
547
- CombineSubstitutionMaps::AtDepth,
548
- baseDepth, origDepth,
549
- baseSig);
542
+ auto &ctx = baseSig->getASTContext ();
543
+
544
+ return get (
545
+ baseSig,
546
+ [&](SubstitutableType *type) -> Type {
547
+ if (auto gp = type->getAs <GenericTypeParamType>()) {
548
+ if (gp->getDepth () >= baseDepth) {
549
+ assert (gp->getDepth () == baseDepth);
550
+ auto substGP = GenericTypeParamType::get (gp->isTypeSequence (),
551
+ gp->getDepth () + origDepth - baseDepth,
552
+ gp->getIndex (), ctx);
553
+ return derivedSig->getSugaredType (substGP);
554
+ }
555
+ }
556
+
557
+ return Type (type).subst (baseSubMap);
558
+ },
559
+ [&](CanType type, Type substType, ProtocolDecl *proto) {
560
+ if (type->getRootGenericParam ()->getDepth () >= baseDepth)
561
+ return ProtocolConformanceRef (proto);
562
+
563
+ if (auto conformance = baseSubMap.lookupConformance (type, proto))
564
+ return conformance;
565
+
566
+ if (substType->isTypeParameter ())
567
+ return ProtocolConformanceRef (proto);
568
+
569
+ return proto->getParentModule ()->lookupConformance (substType, proto);
570
+ });
550
571
}
551
572
552
573
SubstitutionMap
0 commit comments