Skip to content

[Associated type inference] Resolve @_implements on AsyncSequence.Failure #72552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/Sema/AssociatedTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,6 @@ static ResolveWitnessResult resolveTypeWitnessViaLookup(
auto *dc = conformance->getDeclContext();
auto &ctx = dc->getASTContext();

// Prior to Swift 6, don't look for a named type witness for
// AsyncSequence.Failure. We'll always infer it from
// AsyncIteratorProtocol.Failure.
if (isAsyncSequenceFailure(assocType) &&
!ctx.LangOpts.isSwiftVersionAtLeast(6))
return ResolveWitnessResult::Missing;

// Conformances constructed by the ClangImporter should have explicit type
// witnesses already.
if (isa<ClangModuleUnit>(dc->getModuleScopeContext())) {
Expand Down Expand Up @@ -479,10 +472,18 @@ static ResolveWitnessResult resolveTypeWitnessViaLookup(
// Also skip candidates in protocol extensions, because they tend to cause
// request cycles. We'll look at those during associated type inference.
if (assocType->getName() != typeDecl->getName() &&
!(witnessHasImplementsAttrForRequiredName(typeDecl, assocType) &&
!(witnessHasImplementsAttrForExactRequirement(typeDecl, assocType) &&
!typeDecl->getDeclContext()->getSelfProtocolDecl()))
continue;

// Prior to Swift 6, ignore a member named Failure when matching
// AsyncSequence.Failure. We'll infer it from the AsyncIterator.Failure
// instead.
if (isAsyncSequenceFailure(assocType) &&
!ctx.LangOpts.isSwiftVersionAtLeast(6) &&
assocType->getName() == typeDecl->getName())
continue;;

auto *genericDecl = cast<GenericTypeDecl>(typeDecl);

// If the declaration has generic parameters, it cannot witness an
Expand Down
12 changes: 12 additions & 0 deletions test/Concurrency/async_sequence_syntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,15 @@ public struct ReaderSeq: AsyncSequence, Sendable {
func test1() -> Error {
return ReaderSeq.Failure.x
}

@available(SwiftStdlib 5.1, *)
public struct MineOwnIterator<Element>: AsyncSequence, AsyncIteratorProtocol {
public mutating func next() async -> Element? { nil }
public func makeAsyncIterator() -> Self { self }

@_implements(AsyncIteratorProtocol, Failure)
public typealias __AsyncIteratorProtocol_Failure = Never

@_implements(AsyncSequence, Failure)
public typealias __AsyncSequence_Failure = Never
}