@@ -445,7 +445,7 @@ Type TypeSubstituter::transformPrimaryArchetypeType(ArchetypeType *primary,
445
445
return primary;
446
446
447
447
auto known = IFS.substType (primary, level);
448
- ASSERT (known && " Opaque type replacement shouldn't fail" );
448
+ ASSERT (known && " Primary archetype replacement shouldn't fail" );
449
449
450
450
return known;
451
451
}
@@ -459,7 +459,7 @@ TypeSubstituter::transformOpaqueTypeArchetypeType(OpaqueTypeArchetypeType *opaqu
459
459
return std::nullopt;
460
460
461
461
auto known = IFS.substType (opaque, level);
462
- ASSERT (known && " Opaque type replacement shouldn't fail" );
462
+ ASSERT (known && " Opaque archetype replacement shouldn't fail" );
463
463
464
464
// If we return an opaque archetype unchanged, recurse into its substitutions
465
465
// as a special case.
@@ -517,76 +517,18 @@ Type TypeSubstituter::transformDependentMemberType(DependentMemberType *dependen
517
517
auto origBase = dependent->getBase ();
518
518
auto substBase = doIt (origBase, TypePosition::Invariant);
519
519
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
-
539
520
if (auto *selfType = substBase->getAs <DynamicSelfType>())
540
521
substBase = selfType->getSelfType ();
541
522
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);
566
525
567
526
auto proto = assocType->getProtocol ();
568
527
ProtocolConformanceRef conformance =
569
528
IFS.lookupConformance (origBase->getCanonicalType (), substBase,
570
529
proto, level);
571
530
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 ());
590
532
}
591
533
592
534
SubstitutionMap TypeSubstituter::transformSubstitutionMap (SubstitutionMap subs) {
0 commit comments