Skip to content

Commit b087794

Browse files
authored
Merge pull request #72552 from DougGregor/implements-on-asyncsequence-failure-6.0
[Associated type inference] Resolve `@_implements` on AsyncSequence.Failure
2 parents e07e34a + 99742fb commit b087794

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,6 @@ static ResolveWitnessResult resolveTypeWitnessViaLookup(
430430
auto *dc = conformance->getDeclContext();
431431
auto &ctx = dc->getASTContext();
432432

433-
// Prior to Swift 6, don't look for a named type witness for
434-
// AsyncSequence.Failure. We'll always infer it from
435-
// AsyncIteratorProtocol.Failure.
436-
if (isAsyncSequenceFailure(assocType) &&
437-
!ctx.LangOpts.isSwiftVersionAtLeast(6))
438-
return ResolveWitnessResult::Missing;
439-
440433
// Conformances constructed by the ClangImporter should have explicit type
441434
// witnesses already.
442435
if (isa<ClangModuleUnit>(dc->getModuleScopeContext())) {
@@ -479,10 +472,18 @@ static ResolveWitnessResult resolveTypeWitnessViaLookup(
479472
// Also skip candidates in protocol extensions, because they tend to cause
480473
// request cycles. We'll look at those during associated type inference.
481474
if (assocType->getName() != typeDecl->getName() &&
482-
!(witnessHasImplementsAttrForRequiredName(typeDecl, assocType) &&
475+
!(witnessHasImplementsAttrForExactRequirement(typeDecl, assocType) &&
483476
!typeDecl->getDeclContext()->getSelfProtocolDecl()))
484477
continue;
485478

479+
// Prior to Swift 6, ignore a member named Failure when matching
480+
// AsyncSequence.Failure. We'll infer it from the AsyncIterator.Failure
481+
// instead.
482+
if (isAsyncSequenceFailure(assocType) &&
483+
!ctx.LangOpts.isSwiftVersionAtLeast(6) &&
484+
assocType->getName() == typeDecl->getName())
485+
continue;;
486+
486487
auto *genericDecl = cast<GenericTypeDecl>(typeDecl);
487488

488489
// If the declaration has generic parameters, it cannot witness an

test/Concurrency/async_sequence_syntax.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ public struct ReaderSeq: AsyncSequence, Sendable {
119119
func test1() -> Error {
120120
return ReaderSeq.Failure.x
121121
}
122+
123+
@available(SwiftStdlib 5.1, *)
124+
public struct MineOwnIterator<Element>: AsyncSequence, AsyncIteratorProtocol {
125+
public mutating func next() async -> Element? { nil }
126+
public func makeAsyncIterator() -> Self { self }
127+
128+
@_implements(AsyncIteratorProtocol, Failure)
129+
public typealias __AsyncIteratorProtocol_Failure = Never
130+
131+
@_implements(AsyncSequence, Failure)
132+
public typealias __AsyncSequence_Failure = Never
133+
}

0 commit comments

Comments
 (0)