@@ -389,13 +389,49 @@ static void recordTypeWitness(NormalProtocolConformance *conformance,
389389 }
390390}
391391
392+ // / Determine whether this is the AsyncIteratorProtocol.Failure associated type.
393+ static bool isAsyncIteratorProtocolFailure (AssociatedTypeDecl *assocType) {
394+ auto proto = assocType->getProtocol ();
395+ if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol))
396+ return false ;
397+
398+ return assocType->getName () == assocType->getASTContext ().Id_Failure ;
399+ }
400+
401+ // / Determine whether this is the AsyncSequence.Failure associated type.
402+ static bool isAsyncSequenceFailure (AssociatedTypeDecl *assocType) {
403+ auto proto = assocType->getProtocol ();
404+ if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence))
405+ return false ;
406+
407+ return assocType->getName () == assocType->getASTContext ().Id_Failure ;
408+ }
409+
410+ // / Determine whether this is the AsyncIteratorProtocol.Failure or
411+ // / AsyncSequence.Failure associated type.
412+ static bool isAsyncIteratorOrSequenceFailure (AssociatedTypeDecl *assocType) {
413+ auto proto = assocType->getProtocol ();
414+ if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol) &&
415+ !proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence))
416+ return false ;
417+
418+ return assocType->getName () == assocType->getASTContext ().Id_Failure ;
419+ }
420+
392421// / Attempt to resolve a type witness via member name lookup.
393422static ResolveWitnessResult resolveTypeWitnessViaLookup (
394423 NormalProtocolConformance *conformance,
395424 AssociatedTypeDecl *assocType) {
396425 auto *dc = conformance->getDeclContext ();
397426 auto &ctx = dc->getASTContext ();
398427
428+ // Prior to Swift 6, don't look for a named type witness for
429+ // AsyncSequence.Failure. We'll always infer it from
430+ // AsyncIteratorProtocol.Failure.
431+ if (isAsyncSequenceFailure (assocType) &&
432+ !ctx.LangOpts .isSwiftVersionAtLeast (6 ))
433+ return ResolveWitnessResult::Missing;
434+
399435 // Conformances constructed by the ClangImporter should have explicit type
400436 // witnesses already.
401437 if (isa<ClangModuleUnit>(dc->getModuleScopeContext ())) {
@@ -1816,25 +1852,15 @@ next_witness:;
18161852 return result;
18171853}
18181854
1819- // / Determine whether this is AsyncIteratorProtocol.Failure or
1820- // / AsyncSequenceProtoco.Failure associated type.
1821- static bool isAsyncIteratorProtocolFailure (AssociatedTypeDecl *assocType) {
1822- auto proto = assocType->getProtocol ();
1823- if (!proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol) &&
1824- !proto->isSpecificProtocol (KnownProtocolKind::AsyncSequence))
1825- return false ;
1826-
1827- return assocType->getName () == assocType->getASTContext ().Id_Failure ;
1828- }
1829-
18301855// / Determine whether this is AsyncIteratorProtocol.next() function.
18311856static bool isAsyncIteratorProtocolNext (ValueDecl *req) {
18321857 auto proto = dyn_cast<ProtocolDecl>(req->getDeclContext ());
18331858 if (!proto ||
18341859 !proto->isSpecificProtocol (KnownProtocolKind::AsyncIteratorProtocol))
18351860 return false ;
18361861
1837- return req->getName ().getBaseName () == req->getASTContext ().Id_next ;
1862+ return req->getName ().getBaseName () == req->getASTContext ().Id_next &&
1863+ req->getName ().getArgumentNames ().empty ();
18381864}
18391865
18401866InferredAssociatedTypes
@@ -2537,8 +2563,7 @@ std::optional<AbstractTypeWitness>
25372563AssociatedTypeInference::computeFailureTypeWitness (
25382564 AssociatedTypeDecl *assocType,
25392565 ArrayRef<std::pair<ValueDecl *, ValueDecl *>> valueWitnesses) const {
2540- // Inference only applies to AsyncIteratorProtocol.Failure and
2541- // AsyncSequence.Failure.
2566+ // Inference only applies to AsyncIteratorProtocol.Failure.
25422567 if (!isAsyncIteratorProtocolFailure (assocType))
25432568 return std::nullopt ;
25442569
@@ -2582,7 +2607,7 @@ AssociatedTypeInference::computeDefaultTypeWitness(
25822607 AssociatedTypeDecl *assocType) const {
25832608 // Ignore the default for AsyncIteratorProtocol.Failure and
25842609 // AsyncSequence.Failure.
2585- if (isAsyncIteratorProtocolFailure (assocType))
2610+ if (isAsyncIteratorOrSequenceFailure (assocType))
25862611 return std::nullopt ;
25872612
25882613 // Go find a default definition.
@@ -2683,8 +2708,8 @@ AssociatedTypeInference::computeAbstractTypeWitness(
26832708
26842709 // Don't consider the generic parameter names for AsyncSequence.Failure or
26852710 // AsyncIteratorProtocol.Failure; we always rely on inference from next() or
2686- // next(_ :).
2687- if (isAsyncIteratorProtocolFailure (assocType)) {
2711+ // next(isolation :).
2712+ if (isAsyncIteratorOrSequenceFailure (assocType)) {
26882713 // If this is specifically AsyncSequence.Failure with the older associated
26892714 // type inference implementation, our abstract witness is
26902715 // "AsyncIterator.Failure". The new implementation is smart enough to do
@@ -2727,7 +2752,7 @@ Type AssociatedTypeInference::computeGenericParamWitness(
27272752 if (auto genericSig = dc->getGenericSignatureOfContext ()) {
27282753 // Ignore the generic parameters for AsyncIteratorProtocol.Failure and
27292754 // AsyncSequence.Failure.
2730- if (!isAsyncIteratorProtocolFailure (assocType)) {
2755+ if (!isAsyncIteratorOrSequenceFailure (assocType)) {
27312756 for (auto *gp : genericSig.getInnermostGenericParams ()) {
27322757 // Packs cannot witness associated type requirements.
27332758 if (gp->isParameterPack ())
0 commit comments