@@ -490,6 +490,8 @@ class TypeSubstituter : public TypeTransform<TypeSubstituter> {
490490
491491 std::optional<Type> transform (TypeBase *type, TypePosition pos);
492492
493+ Type transformGenericTypeParam (GenericTypeParamType *param, TypePosition pos);
494+
493495 Type transformPackExpansion (PackExpansionType *expand, TypePosition pos);
494496
495497 Type transformPackElement (PackElementType *element, TypePosition pos);
@@ -512,7 +514,7 @@ TypeSubstituter::transform(TypeBase *type, TypePosition position) {
512514 " should not be doing AST type-substitution on a lowered SIL type;"
513515 " use SILType::subst" );
514516
515- auto substOrig = dyn_cast<SubstitutableType >(type);
517+ auto substOrig = dyn_cast<ArchetypeType >(type);
516518 if (!substOrig)
517519 return std::nullopt ;
518520
@@ -532,41 +534,46 @@ TypeSubstituter::transform(TypeBase *type, TypePosition position) {
532534 return known;
533535 }
534536
535- // If we failed to substitute a generic type parameter, give up.
536- if (isa<GenericTypeParamType>(substOrig))
537- return ErrorType::get (type);
538-
539- auto origArchetype = cast<ArchetypeType>(substOrig);
540- if (origArchetype->isRoot ()) {
537+ if (substOrig->isRoot ()) {
541538 // Root opened archetypes are not required to be substituted. Other root
542539 // archetypes must already have been substituted above.
543- if (isa<LocalArchetypeType>(origArchetype )) {
540+ if (isa<LocalArchetypeType>(substOrig )) {
544541 return Type (type);
545542 } else {
546543 return ErrorType::get (type);
547544 }
548545 }
549546
550547 // For nested archetypes, we can substitute the parent.
551- Type origParent = origArchetype ->getParent ();
548+ Type origParent = substOrig ->getParent ();
552549 assert (origParent && " Not a nested archetype" );
553550
554551 // Substitute into the parent type.
555552 Type substParent = doIt (origParent, TypePosition::Invariant);
556553
557554 // If the parent didn't change, we won't change.
558- if (substParent.getPointer () == origArchetype ->getParent ())
555+ if (substParent.getPointer () == substOrig ->getParent ())
559556 return Type (type);
560557
561558 // Get the associated type reference from a child archetype.
562- AssociatedTypeDecl *assocType = origArchetype ->getInterfaceType ()
559+ AssociatedTypeDecl *assocType = substOrig ->getInterfaceType ()
563560 ->castTo <DependentMemberType>()->getAssocType ();
564561
565- return getMemberForBaseType (IFS, origArchetype ->getParent (), substParent,
562+ return getMemberForBaseType (IFS, substOrig ->getParent (), substParent,
566563 assocType, assocType->getName (),
567564 level);
568565}
569566
567+ Type TypeSubstituter::transformGenericTypeParam (GenericTypeParamType *param,
568+ TypePosition pos) {
569+ // If we have a substitution for this type, use it.
570+ if (auto known = IFS.substType (param, level))
571+ return known;
572+
573+ // If we failed to substitute a generic type parameter, give up.
574+ return ErrorType::get (param);
575+ }
576+
570577Type TypeSubstituter::transformPackExpansion (PackExpansionType *expand,
571578 TypePosition pos) {
572579 auto eltTys = IFS.expandPackExpansionType (expand);
0 commit comments