Skip to content

AsyncSequence.prefix(while:) function is unnecessarily marked rethrows #82522

Open
@JohnEstropia

Description

@JohnEstropia

Description

_Concurrency.AsyncSequence

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension AsyncSequence {

    @preconcurrency @inlinable public func prefix(while predicate: @escaping @Sendable (Self.Element) async -> Bool) rethrows -> AsyncPrefixWhileSequence<Self>
}

This causes the compiler to require writing try when one of the inner closures owned by a different method is a throwing closure, even if the closure owned by prefix() is non-throwing

Reproduction

AsyncThrowingStream( // Call can throw but is not marked with 'try'
                        // Call is to 'rethrows' function, but a conformance has a throwing witness
  unfolding: {
    try await Task.sleep(for: .zero)
  }
)
.prefix(while: { _ in true })

Expected behavior

Should not have a compiler error requiring the use of try

Environment

Swift 6.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions