diff --git a/stdlib/public/Concurrency/AsyncIteratorProtocol.swift b/stdlib/public/Concurrency/AsyncIteratorProtocol.swift index 56ff75bc56f..bc390d431bb 100644 --- a/stdlib/public/Concurrency/AsyncIteratorProtocol.swift +++ b/stdlib/public/Concurrency/AsyncIteratorProtocol.swift @@ -111,8 +111,9 @@ public protocol AsyncIteratorProtocol { @available(SwiftStdlib 5.1, *) extension AsyncIteratorProtocol { - /// Default implementation of `next()` in terms of `next()`, which is - /// required to maintain backward compatibility with existing async iterators. + /// Default implementation of `next(isolation:)` in terms of `next()`, which + /// is required to maintain backward compatibility with existing async + /// iterators. @available(SwiftStdlib 6.0, *) @inlinable public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Element? { @@ -123,3 +124,15 @@ extension AsyncIteratorProtocol { } } } + +@available(SwiftStdlib 5.1, *) +extension AsyncIteratorProtocol { + /// Default implementation of `next()` in terms of `next(isolation:)`, which + /// is required to maintain backward compatibility with existing async + /// iterators. + @available(SwiftStdlib 6.0, *) + @inlinable + public mutating func next() async throws(Failure) -> Element? { + return try await next(isolation: nil) + } +} diff --git a/test/Concurrency/async_sequence_rethrows.swift b/test/Concurrency/async_sequence_rethrows.swift index 187af6e903c..9a215f07eda 100644 --- a/test/Concurrency/async_sequence_rethrows.swift +++ b/test/Concurrency/async_sequence_rethrows.swift @@ -75,3 +75,13 @@ enum MyError: Error { func getASequence() -> any AsyncSequence { return ErrorSequence(throwError: MyError.foo) // ERROR: Cannot convert return expression of type 'any Error' to return type 'MyError' } + +// Test the default implementation of next() in terms of next(isolation:). +struct AsyncIteratorWithOnlyNextIsolation: AsyncIteratorProtocol { + public mutating func next(isolation: (any Actor)?) throws(MyError) -> Int? { 0 } +} + +// Test the default implementation of next(isolation:) in terms of next(). +struct AsyncIteratorWithOnlyNext: AsyncIteratorProtocol { + public mutating func next() throws(MyError) -> Int? { 0 } +}