Availability on a generic constraint

Hello, Swift community!

I have a situation where a protocol inheriting from AsyncSequence needs to require Failure to be Never without the whole protocol having to reduce its availability.
I can currently spell this out via an overriding typealias inside the protocol, but the compiler emits a warning with an invalid fix-it that loses the @available attribute, causing a compilation error. Attempting to resolve the error via its own fix-it leads to the @available attribute being applied to the whole protocol, which is a change that is incompatible with the original declaration.

public protocol Producer<Element>: AsyncSequence where Element: Sendable {
    @available(macOS 15.0, tvOS 18.0, iOS 18.0, watchOS 11.0, visionOS 2.0, *)
    typealias Failure = Never // 🟡 Typealias overriding associated type 'Failure' from protocol 'AsyncSequence' is better expressed as same-type constraint on the protocol
}

Is there a warning-free spelling for what I'm trying to achieve, or is this functionality not supported, or is this edge case of the warning an oversight?

3 Likes

Just seems like an oversight to me. Availability limited associated types were only introduced recently to facilitate AsyncSequence’s Failure type and I don’t think the impact on the diagnostic you’re seeing was considered yet.

1 Like