@@ -528,31 +528,23 @@ TypeSubstituter::transform(TypeBase *type, TypePosition position) {
528528
529529Type TypeSubstituter::transformPrimaryArchetypeType (ArchetypeType *primary,
530530 TypePosition position) {
531- // If we have a substitution for this type, use it.
532- if (auto known = IFS.substType (primary, level))
533- return known;
534-
535- if (primary->isRoot ())
536- return ErrorType::get (primary);
537-
538- // For nested archetypes, we can substitute the parent.
539- Type origParent = primary->getParent ();
540- assert (origParent && " Not a nested archetype" );
541-
542- // Substitute into the parent type.
543- Type substParent = doIt (origParent, TypePosition::Invariant);
531+ // If we're not in one of the special modes, map the primary archetype out
532+ // of context, and substitute that instead.
533+ if (!IFS.shouldSubstitutePrimaryArchetypes () &&
534+ !IFS.shouldSubstituteOpaqueArchetypes () &&
535+ !IFS.shouldSubstituteLocalArchetypes ()) {
536+ return doIt (primary->getInterfaceType (), position);
537+ }
544538
545- // If the parent didn't change, we won't change.
546- if (substParent.getPointer () == origParent.getPointer ())
547- return Type (primary);
539+ // Primary types can't normally be directly substituted unless we
540+ // specifically were asked to substitute them.
541+ if (!IFS.shouldSubstitutePrimaryArchetypes ())
542+ return primary;
548543
549- // Get the associated type reference from a child archetype.
550- AssociatedTypeDecl *assocType = primary->getInterfaceType ()
551- ->castTo <DependentMemberType>()->getAssocType ();
544+ auto known = IFS.substType (primary, level);
545+ ASSERT (known && " Opaque type replacement shouldn't fail" );
552546
553- return getMemberForBaseType (IFS, origParent, substParent,
554- assocType, assocType->getName (),
555- level);
547+ return known;
556548}
557549
558550std::optional<Type>
0 commit comments