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-11318] Incorrect "Case will never be executed" warning #53719

Open
swift-ci opened this issue Aug 16, 2019 · 3 comments
Open

[SR-11318] Incorrect "Case will never be executed" warning #53719

swift-ci opened this issue Aug 16, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation pattern matching Feature: pattern matching patterns Feature: patterns SILGen Area → compiler: The SIL generation stage statements Feature: statements swift 5.9 switch cases Feature → statements → switch: 'switch' statement cases switch Feature → statements: 'switch' statements

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Aug 16, 2019

Previous ID SR-11318
Radar None
Original Reporter JaydenIrwin (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 10.3, Mojave 10.14.6

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 938fad3f74db69692d9fbd5816890e38

Issue Description:

The following switch statement always shows "case will never be executed" (twice on the same line), even though it will get executed. touches is of type Set<UITouch>.

switch touches.first!.type {
case .pencil, .stylus:  //        <-- Warning on this line (twice)
    // do stuff
default:
    // do stuff
}
@belkadan
Copy link
Contributor

I only get the warning once, but it's correct-ish since "stylus" is an alias for "pencil". I'll find the bug about fixing the warning text.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue diagnostics QoI Bug: Diagnostics Quality of Implementation pattern matching Feature: pattern matching switch Feature → statements: 'switch' statements statements Feature: statements switch cases Feature → statements → switch: 'switch' statement cases swift 5.0 type checker Area → compiler: Semantic analysis SILGen Area → compiler: The SIL generation stage patterns Feature: patterns missing warning Bug: Missing warning and removed duplicate Resolution: Duplicates another issue type checker Area → compiler: Semantic analysis missing warning Bug: Missing warning labels May 11, 2023
@AnthonyLatsis
Copy link
Collaborator

Reopening and deduplicating because the underlying issues of the duplicate and duplicated issues have diverged as explained below.

#33336 silenced this SIL warning for non-expression patterns, causing the reported test cases to be left completely undiagnosed, which is a regression. The duplicated issue (#50745) is now aimed at diagnosing its test case via the space engine. On the other hand, the test case reported here cannot be diagnosed via the space engine by design, so the SIL warning must be reinstated to accommodate this case before we address the wording of the message.

@theblixguy Tagging you since you authored the aforementioned PR.

@AnthonyLatsis
Copy link
Collaborator

Meanwhile, here is a self-contained reproduction of the misleading message:

enum E {
  case a

  static let b = E.a
}

func foo(e: E) {
  switch e {
    case .a, .b: break
    default: break
  }
}
warning: case will never be executed
    case .a, .b: break
    ^

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 diagnostics QoI Bug: Diagnostics Quality of Implementation pattern matching Feature: pattern matching patterns Feature: patterns SILGen Area → compiler: The SIL generation stage statements Feature: statements swift 5.9 switch cases Feature → statements → switch: 'switch' statement cases switch Feature → statements: 'switch' statements
Projects
None yet
Development

No branches or pull requests

3 participants