[SR-2153] Deprecation warning despite #available check
| Previous ID | SR-2153 |
| Radar | None |
| Original Reporter | @jadengeller |
| Type | Bug |
Attachment: Download
Environment
Xcode 8
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Standard Library |
| Labels | Bug, SDKOverlay |
| Assignee | @devincoughlin |
| Priority | Medium |
md5: 886c724a1a911dff6105c7227062f318
cloned to:
- SR-2154 Don't allow wildcard platform in @available with version
- SR-2155 Change interpretation of * in @available()
Issue Description:
The following code shows a deprecation warning on `priorityBackground` when the deployment target is set to OS X 10.9.
import Foundation
let attributes: DispatchQueue.GlobalAttributes
if #available(OSX 10.10, *) {
attributes = DispatchQueue.GlobalAttributes.qosBackground
} else {
attributes = DispatchQueue.GlobalAttributes.priorityBackground
}
It looks like some of the Dispatch overlay availability attributes are wonky:
{{
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(*, deprecated: 8.0, message: "Use qos attributes instead")
public static let priorityBackground: DispatchQueue.GlobalAttributes
}}
This says priorityBackground is deprecated on all OSes on version 8.0. (This means the compiler thinks was it deprecated on macOS 8.0, which was released in 1997.) Since the minimum deployment target of the attached project is 10.9 and 8.0 < 10.9 the compiler warns that the API is deprecated on all potential deployment target versions.
There are a couple of issues going on here:
(1) We should never allow the wildcard platform in an @available with a specific version. It never makes sense to say "this declaration was deprecated on all platforms in version 4.0)" and so Sema should treat it as an error.
(2) The current interpretation of * in @available is counter-intuitive and differs from its interpretation in #available. In my opinion, the natural interpretation of:
{{
@available(OSX, deprecated=10.10)
@available(*, deprecated)
func foo() { }
}}
is "foo() was deprecated on OSX in version 10.10 and is deprecated for all versions on all other platforms."
Unfortunately, the current interpretation is "foo() is deprecated on all versions of all platforms" – that is, the * wins. This is in contrast to the interpretation of #available where '*' means "all other platforms not explicitly listed"
(3) Regardless of (1) and (2) we need to fix the false positive warnings that users are being now. With the existing compiler, the best way to do this is to update the @available deprecations to explicitly mention watchOS and tvOS:
{{
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
@available(watchOS, deprecated, message: "Use qos attributes instead")
@available(tvOS, deprecated, message: "Use qos attributes instead")
public static let priorityBackground: DispatchQueue.GlobalAttributes
}}
Let's use this SR to track (3), but I think (2) is quite important. I'll file a separate SR for it.
These APIs were renamed in 8ac413a0b5a9f927f44438df3376a7757f607953. They are still misannotated, though.
There is a fix for the mis-annotations in https://github.com/apple/swift/pull/3797
Should this be closed as the mis-annotation fix PR is merged?