@@ -4390,6 +4390,19 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
4390
4390
if (auto *selfType = substBase->getAs <DynamicSelfType>())
4391
4391
substBase = selfType->getSelfType ();
4392
4392
4393
+ // If the parent is a type variable or a member rooted in a type variable,
4394
+ // or if the parent is a type parameter, we're done. Also handle
4395
+ // UnresolvedType here, which can come up in diagnostics.
4396
+ if (substBase->isTypeVariableOrMember () ||
4397
+ substBase->isTypeParameter () ||
4398
+ substBase->is <UnresolvedType>())
4399
+ return getDependentMemberType (substBase);
4400
+
4401
+ // All remaining cases require an associated type declaration and not just
4402
+ // the name of a member type.
4403
+ if (!assocType)
4404
+ return failed ();
4405
+
4393
4406
// If the parent is an archetype, extract the child archetype with the
4394
4407
// given name.
4395
4408
if (auto archetypeParent = substBase->getAs <ArchetypeType>()) {
@@ -4402,61 +4415,46 @@ static Type getMemberForBaseType(LookupConformanceFn lookupConformances,
4402
4415
return failed ();
4403
4416
}
4404
4417
4405
- // If the parent is a type variable or a member rooted in a type variable,
4406
- // or if the parent is a type parameter, we're done. Also handle
4407
- // UnresolvedType here, which can come up in diagnostics.
4408
- if (substBase->isTypeVariableOrMember () ||
4409
- substBase->isTypeParameter () ||
4410
- substBase->is <UnresolvedType>())
4411
- return getDependentMemberType (substBase);
4418
+ auto proto = assocType->getProtocol ();
4419
+ ProtocolConformanceRef conformance =
4420
+ lookupConformances (origBase->getCanonicalType (), substBase, proto);
4412
4421
4413
- // Retrieve the member type with the given name.
4414
-
4415
- // If we know the associated type, look in the witness table.
4416
- if (assocType) {
4417
- auto proto = assocType->getProtocol ();
4418
- ProtocolConformanceRef conformance =
4419
- lookupConformances (origBase->getCanonicalType (), substBase, proto);
4420
-
4421
- if (conformance.isInvalid ())
4422
- return failed ();
4422
+ if (conformance.isInvalid ())
4423
+ return failed ();
4423
4424
4424
- Type witnessTy;
4425
+ Type witnessTy;
4425
4426
4426
- // Retrieve the type witness.
4427
- if (conformance.isPack ()) {
4428
- auto *packConformance = conformance.getPack ();
4427
+ // Retrieve the type witness.
4428
+ if (conformance.isPack ()) {
4429
+ auto *packConformance = conformance.getPack ();
4429
4430
4430
- witnessTy = packConformance->getAssociatedType (
4431
- assocType->getDeclaredInterfaceType ());
4432
- } else if (conformance.isConcrete ()) {
4433
- auto witness =
4434
- conformance.getConcrete ()->getTypeWitnessAndDecl (assocType, options);
4431
+ witnessTy = packConformance->getAssociatedType (
4432
+ assocType->getDeclaredInterfaceType ());
4433
+ } else if (conformance.isConcrete ()) {
4434
+ auto witness =
4435
+ conformance.getConcrete ()->getTypeWitnessAndDecl (assocType, options);
4435
4436
4436
- witnessTy = witness.getWitnessType ();
4437
- if (!witnessTy || witnessTy->hasError ())
4438
- return failed ();
4437
+ witnessTy = witness.getWitnessType ();
4438
+ if (!witnessTy || witnessTy->hasError ())
4439
+ return failed ();
4439
4440
4440
- // This is a hacky feature allowing code completion to migrate to
4441
- // using Type::subst() without changing output.
4442
- if (options & SubstFlags::DesugarMemberTypes) {
4443
- if (auto *aliasType = dyn_cast<TypeAliasType>(witnessTy.getPointer ()))
4444
- witnessTy = aliasType->getSinglyDesugaredType ();
4441
+ // This is a hacky feature allowing code completion to migrate to
4442
+ // using Type::subst() without changing output.
4443
+ if (options & SubstFlags::DesugarMemberTypes) {
4444
+ if (auto *aliasType = dyn_cast<TypeAliasType>(witnessTy.getPointer ()))
4445
+ witnessTy = aliasType->getSinglyDesugaredType ();
4445
4446
4446
- // Another hack. If the type witness is a opaque result type. They can
4447
- // only be referred using the name of the associated type.
4448
- if (witnessTy->is <OpaqueTypeArchetypeType>())
4449
- witnessTy = witness.getWitnessDecl ()->getDeclaredInterfaceType ();
4450
- }
4447
+ // Another hack. If the type witness is a opaque result type. They can
4448
+ // only be referred using the name of the associated type.
4449
+ if (witnessTy->is <OpaqueTypeArchetypeType>())
4450
+ witnessTy = witness.getWitnessDecl ()->getDeclaredInterfaceType ();
4451
4451
}
4452
-
4453
- if (!witnessTy || witnessTy->is <ErrorType>())
4454
- return failed ();
4455
-
4456
- return witnessTy;
4457
4452
}
4458
4453
4459
- return failed ();
4454
+ if (!witnessTy || witnessTy->is <ErrorType>())
4455
+ return failed ();
4456
+
4457
+ return witnessTy;
4460
4458
}
4461
4459
4462
4460
ProtocolConformanceRef LookUpConformanceInModule::
0 commit comments