@@ -1384,6 +1384,19 @@ AssociatedTypeDecl *AssociatedTypeInference::inferAbstractTypeWitnesses(
1384
1384
for (auto *assocType : unresolvedAssocTypes) {
1385
1385
auto resolvedTy = system.getResolvedTypeWitness (assocType->getName ());
1386
1386
1387
+ resolvedTy = resolvedTy.transformRec ([&](Type ty) -> llvm::Optional<Type> {
1388
+ if (auto *gp = ty->getAs <GenericTypeParamType>()) {
1389
+ // FIXME: 'computeFixedTypeWitness' uses 'getReducedType',
1390
+ // so if a generic parameter is canonical here, it's 'Self'.
1391
+ if (gp->isCanonical () ||
1392
+ isa<ProtocolDecl>(gp->getDecl ()->getDeclContext ()->getAsDecl ())) {
1393
+ return adoptee;
1394
+ }
1395
+ }
1396
+
1397
+ return llvm::None;
1398
+ });
1399
+
1387
1400
typeWitnesses.insert (assocType, {resolvedTy, reqDepth});
1388
1401
1389
1402
if (auto *defaultedAssocType =
@@ -1399,11 +1412,27 @@ AssociatedTypeDecl *AssociatedTypeInference::inferAbstractTypeWitnesses(
1399
1412
// Try to compute the type without the aid of a specific potential
1400
1413
// witness.
1401
1414
if (const auto &typeWitness = computeAbstractTypeWitness (assocType)) {
1415
+ auto resolvedTy = typeWitness->getType ();
1416
+
1417
+ resolvedTy = resolvedTy.transformRec ([&](Type ty) -> llvm::Optional<Type> {
1418
+ if (auto *gp = ty->getAs <GenericTypeParamType>()) {
1419
+ // FIXME: 'computeFixedTypeWitness' uses 'getReducedType',
1420
+ // so if a generic parameter is canonical here, it's 'Self'.
1421
+ if (gp->isCanonical () ||
1422
+ isa<ProtocolDecl>(gp->getDecl ()->getDeclContext ()->getAsDecl ())) {
1423
+ return adoptee;
1424
+ }
1425
+ }
1426
+
1427
+ return llvm::None;
1428
+ });
1429
+
1402
1430
// Record the type witness immediately to make it available
1403
1431
// for substitutions into other tentative type witnesses.
1404
- typeWitnesses.insert (assocType, {typeWitness-> getType () , reqDepth});
1432
+ typeWitnesses.insert (assocType, {resolvedTy , reqDepth});
1405
1433
1406
- abstractTypeWitnesses.push_back (std::move (typeWitness.value ()));
1434
+ abstractTypeWitnesses.emplace_back (assocType, resolvedTy,
1435
+ typeWitness->getDefaultedAssocType ());
1407
1436
continue ;
1408
1437
}
1409
1438
@@ -1431,7 +1460,7 @@ AssociatedTypeDecl *AssociatedTypeInference::inferAbstractTypeWitnesses(
1431
1460
Type type = witness.getType ();
1432
1461
1433
1462
// Replace type parameters with other known or tentative type witnesses.
1434
- if (type->hasTypeParameter ()) {
1463
+ if (type->hasDependentMember () || type-> hasTypeParameter ()) {
1435
1464
// FIXME: We should find a better way to detect and reason about these
1436
1465
// cyclic solutions so that we can spot them earlier and express them in
1437
1466
// diagnostics.
@@ -1440,17 +1469,6 @@ AssociatedTypeDecl *AssociatedTypeInference::inferAbstractTypeWitnesses(
1440
1469
1441
1470
std::function<Type (Type)> substCurrentTypeWitnesses;
1442
1471
substCurrentTypeWitnesses = [&](Type ty) -> Type {
1443
- if (auto *gp = ty->getAs <GenericTypeParamType>()) {
1444
- // FIXME: 'computeFixedTypeWitness' uses 'getReducedType',
1445
- // so if a generic parameter is canonical here, it's 'Self'.
1446
- if (gp->isCanonical () ||
1447
- isa<ProtocolDecl>(gp->getDecl ()->getDeclContext ()->getAsDecl ())) {
1448
- return adoptee;
1449
- }
1450
-
1451
- return ty;
1452
- }
1453
-
1454
1472
auto *const dmt = ty->getAs <DependentMemberType>();
1455
1473
if (!dmt) {
1456
1474
return ty;
0 commit comments