-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Previous ID | SR-11864 |
Radar | rdar://problem/57508973 |
Original Reporter | @karwa |
Type | Bug |
Additional Detail from JIRA
Votes | 0 |
Component/s | |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: aa265d1621de94b205e34a88cfbf1b9e
relates to:
- SR-11647 Swift 5.1 on Linux: Regression in OperationQueue concurrency
Issue Description:
Example background:
-
CGColor.init(red:green:blue:alpha🙂 is not available on tvOS
-
CGColor.init(srgbRed:green:blue:alpha) is `@available(tvOS 13, *)`
Example:
import CoreGraphics
public extension Color {
@available(tvOS 13, watchOS 13, *)
var cgColor : CGColor {
if #available(OSX 10.15, iOS 13, *) {
return CGColor(srgbRed: CGFloat(r),
green: CGFloat(g),
blue: CGFloat(b),
alpha: CGFloat(a))
} else {
// ERROR: CGColor.init(red:...) is not available on tvOS.
return CGColor(red: CGFloat(r),
green: CGFloat(g),
blue: CGFloat(b),
alpha: CGFloat(a))
}
}
}
}
Compiling for the tvOS simulator, Xcode 11.2.1 (11B500)
The compiler complains about the unavailable initialiser in the "else" branch of the OSX/iOS conditional and won't compile this code. Despite the fact that the #available condition will always be true for tvOS, so it will never hit that "else" branch.
There is a workaround, which is to wrap the initialiser (still in the "else" branch) with:
#if !os(tvOS)
return CGColor(...)
#endif
Which is also strange, because now we're not returning anything on the "else" branch, but the compiler seems satisfied that it's dead and doesn't complain. If it knows that, it could also allow the use of the unavailable initialiser.