Skip to content

[SR-8213] Compiler may indicate "case will never be executed" even if it is unavoidable to execute the case in switch statement. #50745

Open
@YOCKOW

Description

@YOCKOW
Previous ID SR-8213
Radar None
Original Reporter @YOCKOW
Type Bug
Environment
  • OS: macOS, Ubuntu 16.04

  • Swift: 4.1.2, 4.2-DEVELOPMENT-SNAPSHOT-2018-07-08

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee Gabriel Igliozzi (JIRA)
Priority Medium

md5: df5f44ab5b8a1d3c8ee6ed4a803d858c

is duplicated by:

  • SR-11318 Incorrect "Case will never be executed" warning

Issue Description:

(As I commented on SR-8208,)
The compiler shows a wrong warning, when the following code is compiled:

enum E {
  case a // only one case
}

func f(_ e0:E, _ e1:E) {
  switch (e0, e1) {
  case (.a, _): print("e0 is .a") // -> No warning.
  }
  
  switch (e0, e1) {
  case (.a, _), (_, .a): print("e0 or e1 is .a") // -> warning: case will never be executed
  }
}

f(.a, .a)

Consideration

  • The warning should be
    • case will be always executed
    • (_, .a) will never match
    • ... and so on

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationgood first issueGood for newcomerspattern matchingFeature: pattern matchingpatternsFeature: patternsstatementsFeature: statementsswift 5.9switchFeature → statements: 'switch' statementsswitch casesFeature → statements → switch: 'switch' statement casestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions