You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below produces a deprecation warning despite the fact that it never calls `foo` on OS versions where it is deprecated:
@available(iOS, deprecated: 13.0)
func foo() {}
func test() {
if #available(iOS 13.0, *) { return }
foo() // warning: 'foo' was deprecated in iOS 13
}
I expected the compiler to realize that control can never progress from within the body of the if statement to the call to `foo`, so the call can never be executed on iOS 13+. (The compiler is clearly able to do such control flow analysis, since it is part of how guard statements work.)
A workaround is to wrap the call in an else block:
func test2() {
if #available(iOS 13.0, *) {
return
} else {
foo() // No warning
}
}
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: bbc582f21d7894280e410fde5bd9f77f
Issue Description:
Adapted from https://twitter.com/steipete/status/1279030286584553472:
The code below produces a deprecation warning despite the fact that it never calls `foo` on OS versions where it is deprecated:
I expected the compiler to realize that control can never progress from within the body of the if statement to the call to `foo`, so the call can never be executed on iOS 13+. (The compiler is clearly able to do such control flow analysis, since it is part of how guard statements work.)
A workaround is to wrap the call in an else block:
The text was updated successfully, but these errors were encountered: