Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13143] Spurious deprecation warnings in certain control flows #55590

Open
lorentey opened this issue Jul 4, 2020 · 2 comments
Open

[SR-13143] Spurious deprecation warnings in certain control flows #55590

lorentey opened this issue Jul 4, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@lorentey
Copy link
Member

lorentey commented Jul 4, 2020

Previous ID SR-13143
Radar rdar://problem/65098260
Original Reporter @lorentey
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

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:

@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
    }
}
@lorentey
Copy link
Member Author

lorentey commented Jul 4, 2020

@swift-ci create

@typesanitizer
Copy link

> A workaround is to wrap the call in an else block:

(T_T). Hey at least there is a workaround, even if that means that equivalent programs emit different diagnostics.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants