Open karwa opened 4 years ago
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.
The program should type-check regardless of whether some conditions are statically known to be true or false. So this behavior is ok IMO.
There is a workaround, which is to wrap the initialiser (still in the "else" branch) with: [..]
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.
Hmm, that shouldn't be happening if you compile for tvOS. To me, this seems like the buggy behavior.
@swift-ci create
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: aa265d1621de94b205e34a88cfbf1b9erelates to:
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:
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:
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.