@@ -300,7 +300,7 @@ static void recordTypeWitness(NormalProtocolConformance *conformance,
300
300
301
301
// Construct the availability of the type witnesses based on the
302
302
// availability of the enclosing type and the associated type.
303
- const Decl * availabilitySources[2 ] = {dc->getAsDecl (), assocType };
303
+ const Decl *availabilitySources[2 ] = { dc->getAsDecl (), assocType };
304
304
AvailabilityInference::applyInferredAvailableAttrs (
305
305
aliasDecl, availabilitySources, ctx);
306
306
@@ -2299,10 +2299,29 @@ AssociatedTypeInference::computeAbstractTypeWitness(
2299
2299
if (const auto &typeWitness = computeDefaultTypeWitness (assocType))
2300
2300
return typeWitness;
2301
2301
2302
- // Ignore the default for AsyncIteratorProtocol.Failure and
2303
- // AsyncSequence.Failure. We use the next() function to do inference.
2304
- if (isAsyncIteratorProtocolFailure (assocType))
2302
+ // Don't consider the generic parameter names for AsyncSequence.Failure or
2303
+ // AsyncIteratorProtocol.Failure; we always rely on inference from next() or
2304
+ // next(_:).
2305
+ if (isAsyncIteratorProtocolFailure (assocType)) {
2306
+ // If this is specifically AsyncSequence.Failure with the older associated
2307
+ // type inference implementation, our abstract witness is
2308
+ // "AsyncIterator.Failure". The new implementation is smart enough to do
2309
+ // this from the same-type constraint.
2310
+ if (!ctx.LangOpts .EnableExperimentalAssociatedTypeInference &&
2311
+ proto == assocType->getProtocol () &&
2312
+ proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence)) {
2313
+ auto iterAssoc = proto->getAssociatedType (ctx.Id_AsyncIterator );
2314
+ auto iteratorProto =
2315
+ ctx.getProtocol (KnownProtocolKind::AsyncIteratorProtocol);
2316
+ auto iteratorFailure = iteratorProto->getAssociatedType (ctx.Id_Failure );
2317
+ Type iterType = DependentMemberType::get (
2318
+ proto->getSelfInterfaceType (), iterAssoc);
2319
+ Type depType = DependentMemberType::get (iterType, iteratorFailure);
2320
+ return AbstractTypeWitness (assocType, depType);
2321
+ }
2322
+
2305
2323
return llvm::None;
2324
+ }
2306
2325
2307
2326
// If there is a generic parameter of the named type, use that.
2308
2327
if (auto genericSig = dc->getGenericSignatureOfContext ()) {
0 commit comments