@@ -445,7 +445,7 @@ Type TypeSubstituter::transformPrimaryArchetypeType(ArchetypeType *primary,
445445 return primary;
446446
447447 auto known = IFS.substType (primary, level);
448- ASSERT (known && " Opaque type replacement shouldn't fail" );
448+ ASSERT (known && " Primary archetype replacement shouldn't fail" );
449449
450450 return known;
451451}
@@ -459,7 +459,7 @@ TypeSubstituter::transformOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *opaqu
459459 return std::nullopt ;
460460
461461 auto known = IFS.substType (opaque, level);
462- ASSERT (known && " Opaque type replacement shouldn't fail" );
462+ ASSERT (known && " Opaque archetype replacement shouldn't fail" );
463463
464464 // If we return an opaque archetype unchanged, recurse into its substitutions
465465 // as a special case.
@@ -517,76 +517,18 @@ Type TypeSubstituter::transformDependentMemberType(DependentMemberType *dependen
517517 auto origBase = dependent->getBase ();
518518 auto substBase = doIt (origBase, TypePosition::Invariant);
519519
520- auto *assocType = dependent->getAssocType ();
521-
522- // Produce a dependent member type for the given base type.
523- auto getDependentMemberType = [&](Type baseType) {
524- if (assocType)
525- return DependentMemberType::get (baseType, assocType);
526-
527- return DependentMemberType::get (baseType, dependent->getName ());
528- };
529-
530- // Produce a failed result.
531- auto failed = [&]() -> Type {
532- Type baseType = ErrorType::get (substBase);
533- if (assocType)
534- return DependentMemberType::get (baseType, assocType);
535-
536- return DependentMemberType::get (baseType, dependent->getName ());
537- };
538-
539520 if (auto *selfType = substBase->getAs <DynamicSelfType>())
540521 substBase = selfType->getSelfType ();
541522
542- // If the parent is a type variable or a member rooted in a type variable,
543- // or if the parent is a type parameter, we're done. Also handle
544- // UnresolvedType here, which can come up in diagnostics.
545- if (substBase->isTypeVariableOrMember () ||
546- substBase->isTypeParameter () ||
547- substBase->is <UnresolvedType>())
548- return getDependentMemberType (substBase);
549-
550- // All remaining cases require an associated type declaration and not just
551- // the name of a member type.
552- if (!assocType)
553- return failed ();
554-
555- // If the parent is an archetype, extract the child archetype with the
556- // given name.
557- if (auto archetypeParent = substBase->getAs <ArchetypeType>()) {
558- if (Type memberArchetypeByName = archetypeParent->getNestedType (assocType))
559- return memberArchetypeByName;
560-
561- // If looking for an associated type and the archetype is constrained to a
562- // class, continue to the default associated type lookup
563- if (!assocType || !archetypeParent->getSuperclass ())
564- return failed ();
565- }
523+ auto *assocType = dependent->getAssocType ();
524+ ASSERT (assocType);
566525
567526 auto proto = assocType->getProtocol ();
568527 ProtocolConformanceRef conformance =
569528 IFS.lookupConformance (origBase->getCanonicalType (), substBase,
570529 proto, level);
571530
572- if (conformance.isInvalid ())
573- return failed ();
574-
575- Type witnessTy;
576-
577- // Retrieve the type witness.
578- if (conformance.isPack ()) {
579- witnessTy = conformance.getPack ()->getTypeWitness (assocType,
580- IFS.getOptions ());
581- } else if (conformance.isConcrete ()) {
582- witnessTy = conformance.getConcrete ()->getTypeWitness (assocType,
583- IFS.getOptions ());
584- }
585-
586- if (!witnessTy || witnessTy->is <ErrorType>())
587- return failed ();
588-
589- return witnessTy;
531+ return conformance.getTypeWitness (substBase, assocType, IFS.getOptions ());
590532}
591533
592534SubstitutionMap TypeSubstituter::transformSubstitutionMap (SubstitutionMap subs) {
0 commit comments