Contradictory `@available`s are required?

I'm working on some code that uses UIBarButtonItem.flexibleSpace (introduced in iOS 14 and tvOS 14) and UIToolbar (doesn't exist in tvOS). Turns out those availabilities interact in a very unintuitive way: the required annotations are

@available(iOS 14, macCatalyst 14, tvOS 14, *)
@available(tvOS, unavailable)

If I remove the tvOS 14 from the first available list, it fails to compile, even though it's unavailable on tvOS anyways.

Is this expected? Why would that be the case?

Relevant PR: Build UIKitBackend in CI by bbrk24 · Pull Request #119 · stackotter/swift-cross-ui · GitHub

It's a long standing issue; there's no point in diagnosing potential unavailability on a given platform in a context that is unavailable on that platform, but the compiler implementation doesn't yet take that into account. I'm hoping to address it in the Swift 6.2 compiler because the fix should be easier now thanks to some refactoring.

Note that you can spell the workaround this way if you find it makes it easier to follow:

@available(iOS 14, macCatalyst 14, *)
@available(tvOS, unavailable, introduced: 14)
3 Likes