@@ -563,35 +563,15 @@ TypeSubstituter::transformOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *opaqu
563563 if (!IFS.shouldSubstituteOpaqueArchetypes ())
564564 return std::nullopt ;
565565
566- // If we have a substitution for this type, use it.
567- if (auto known = IFS.substType (opaque, level)) {
568- if (known->getCanonicalType () == opaque->getCanonicalType ())
569- return std::nullopt ; // Recursively process the substitutions of the
570- // opaque type archetype.
571- return known;
572- }
573-
574- if (opaque->isRoot ())
575- return ErrorType::get (opaque);
576-
577- // For nested archetypes, we can substitute the parent.
578- Type origParent = opaque->getParent ();
579- assert (origParent && " Not a nested archetype" );
580-
581- // Substitute into the parent type.
582- Type substParent = doIt (origParent, TypePosition::Invariant);
583-
584- // If the parent didn't change, we won't change.
585- if (substParent.getPointer () == origParent.getPointer ())
586- return Type (opaque);
587-
588- // Get the associated type reference from a child archetype.
589- AssociatedTypeDecl *assocType = opaque->getInterfaceType ()
590- ->castTo <DependentMemberType>()->getAssocType ();
591-
592- return getMemberForBaseType (IFS, origParent, substParent,
593- assocType, assocType->getName (),
594- level);
566+ auto known = IFS.substType (opaque, level);
567+ ASSERT (known && " Opaque type replacement shouldn't fail" );
568+
569+ // If we return an opaque archetype unchanged, recurse into its substitutions
570+ // as a special case.
571+ if (known->getCanonicalType () == opaque->getCanonicalType ())
572+ return std::nullopt ; // Recursively process the substitutions of the
573+ // opaque type archetype.
574+ return known;
595575}
596576
597577std::optional<Type>
0 commit comments