@@ -1185,7 +1185,9 @@ AssociatedTypeDecl *AssociatedTypeInference::completeSolution(
11851185 for (const auto &witness : abstractTypeWitnesses) {
11861186 Type type = witness.getType ();
11871187 if (type->hasTypeParameter ()) {
1188- if (witness.getKind () != AbstractTypeWitnessKind::GenericParam) {
1188+ if (witness.getKind () == AbstractTypeWitnessKind::GenericParam) {
1189+ type = type = dc->mapTypeIntoContext (type);
1190+ } else {
11891191 // Replace type parameters with other known or tentative type witnesses.
11901192 type = type.subst (
11911193 [&](SubstitutableType *type) {
@@ -1200,23 +1202,26 @@ AssociatedTypeDecl *AssociatedTypeInference::completeSolution(
12001202 if (type->hasError ())
12011203 return witness.getAssocType ();
12021204
1203- // FIXME: If we still have a type parameter and it isn't a generic
1204- // parameter of the conforming nominal, it's either a cycle or a
1205- // solution that is beyond the current algorithm, i.e.
1206- //
1205+ // FIXME: If mapping into context yields an error, or we still have a
1206+ // type parameter despite not having a generic environment, then a type
1207+ // parameter was sent to a tentative type witness that itself is a type
1208+ // parameter, and the solution is cyclic, e.g. { A := B.A, B := A.B },
1209+ // or beyond the current algorithm, e.g.
12071210 // protocol P {
12081211 // associatedtype A = B
12091212 // associatedtype B = C
12101213 // associatedtype C = Int
12111214 // }
12121215 // struct Conformer: P {}
1213- if (type->hasTypeParameter () &&
1214- !adoptee->getAnyNominal ()->isGeneric ()) {
1216+ if (dc->getGenericEnvironmentOfContext ()) {
1217+ type = dc->mapTypeIntoContext (type);
1218+
1219+ if (type->hasError ())
1220+ return witness.getAssocType ();
1221+ } else if (type->hasTypeParameter ()) {
12151222 return witness.getAssocType ();
12161223 }
12171224 }
1218-
1219- type = dc->mapTypeIntoContext (type);
12201225 }
12211226
12221227 if (const auto &failed = checkTypeWitness (type, witness.getAssocType (),
0 commit comments