@@ -129,6 +129,10 @@ where Base.Element: Sendable, Base: _SendableMetatype, Base.AsyncIterator: _Send
129129 // **Usage**: Tracks buffer position and manages async continuations
130130 // **Cleanup**: Automatically unregisters and cancels pending operations on deinit
131131 final class Side {
132+ // Due to a runtime crash in 1.0 compatible versions, it's not possible to handle
133+ // a generic failure constrained to Base.Failure. We handle inner failure with a `any Error`
134+ // and force unwrap it to the generic 1.2 generic type on the outside Iterator.
135+ typealias Failure = any Error
132136 // Tracks the state of a single consumer's iteration.
133137 //
134138 // - `continuation`: The continuation waiting for the next element (nil if not waiting)
@@ -180,6 +184,7 @@ where Base.Element: Sendable, Base: _SendableMetatype, Base.AsyncIterator: _Send
180184 // All operations are synchronized using a `Mutex` to ensure thread-safe access
181185 // to the shared state across multiple concurrent consumers.
182186 final class Iteration : Sendable {
187+ typealias Failure = Side . Failure
183188 // Represents the state of the background task that consumes the source sequence.
184189 //
185190 // The iteration task goes through several states during its lifecycle:
@@ -586,7 +591,7 @@ where Base.Element: Sendable, Base: _SendableMetatype, Base.AsyncIterator: _Send
586591 }
587592 }
588593 } catch {
589- emit ( . failure( error as! Failure ) )
594+ emit ( . failure( error) )
590595 }
591596 }
592597
@@ -695,8 +700,10 @@ where Base.Element: Sendable, Base: _SendableMetatype, Base.AsyncIterator: _Send
695700}
696701
697702@available ( AsyncAlgorithms 1 . 1 , * )
698- extension AsyncShareSequence : AsyncSequence , AsyncFailureBackportable {
703+ extension AsyncShareSequence : AsyncSequence {
699704 public typealias Element = Base . Element
705+ @available ( AsyncAlgorithms 1 . 2 , * )
706+ public typealias Failure = Base . Failure
700707 public struct Iterator : AsyncIteratorProtocol , _SendableMetatype {
701708 let side : Side
702709
@@ -707,21 +714,23 @@ extension AsyncShareSequence: AsyncSequence, AsyncFailureBackportable {
707714 mutating public func next( ) async rethrows -> Element ? {
708715 try await side. next ( isolation: nil )
709716 }
710-
711- // mutating public func next(isolation actor: isolated (any Actor)?) async throws(Self.BackportableFailure) -> Element? {
712- // try await side.next(isolation: actor)
713- // }
717+
718+ @available ( AsyncAlgorithms 1 . 2 , * )
719+ mutating public func next( isolation actor : isolated ( any Actor ) ? ) async throws ( Failure) -> Element ? {
720+ do {
721+ return try await side. next ( isolation: actor )
722+ } catch {
723+ // It's guaranteed to match `Failure` but we are keeping the internal `Side` and `Iteration`
724+ // constrained to `any Error` to prevent a compiler bug visible at runtime
725+ // on pre 1.2 operating systems
726+ throw error as! Failure
727+ }
728+ }
714729 }
715730
716731 public func makeAsyncIterator( ) -> Iterator {
717732 Iterator ( extent. iteration)
718733 }
719734}
720735
721- @available ( AsyncAlgorithms 1 . 2 , * )
722- extension AsyncShareSequence . Iterator {
723- mutating public func next( isolation actor : isolated ( any Actor ) ? ) async throws ( Base. Failure) -> Base . Element ? {
724- try await side. next ( isolation: actor )
725- }
726- }
727736#endif
0 commit comments