Skip to content

[SR-12231] Redundant warnings about inaccessible cases #54657

@jckarter

Description

@jckarter
Previous ID SR-12231
Radar rdar://problem/59655513
Original Reporter @jckarter
Type Task
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Task
Assignee @theblixguy
Priority Medium

md5: b93ca2cf64657801fb589e8fb2a731b9

Issue Description:

If you have a switch with redundant cases, you get warnings about it twice:

enum Foo {
  case foo(bar: Int)
  case boo(bar: Int, bas: Int)
}

func switchFoo(x: Foo) {
  switch x {
  case .foo:
    print()
  case .foo(let bar):
    print()
  case .foo(let butt):
    print()
  case .foo(bar: let bar):
    print()
  case .boo:
    print()
  case .boo(let bar, let bas):
    print()
  }
}
/Users/jgroff/foo.swift:10:8: warning: case is already handled by previous patterns; consider removing it
  case .foo(let bar):
       ^~~~~~~~~~~~~
/Users/jgroff/foo.swift:12:8: warning: case is already handled by previous patterns; consider removing it
  case .foo(let butt):
       ^~~~~~~~~~~~~~
/Users/jgroff/foo.swift:14:8: warning: case is already handled by previous patterns; consider removing it
  case .foo(bar: let bar):
       ^~~~~~~~~~~~~~~~~~
/Users/jgroff/foo.swift:18:8: warning: case is already handled by previous patterns; consider removing it
  case .boo(let bar, let bas):
       ^~~~~~~~~~~~~~~~~~~~~~
/Users/jgroff/foo.swift:10:3: warning: case will never be executed
  case .foo(let bar):
  ^
/Users/jgroff/foo.swift:12:3: warning: case will never be executed
  case .foo(let butt):
  ^
/Users/jgroff/foo.swift:14:3: warning: case will never be executed
  case .foo(bar: let bar):
  ^
/Users/jgroff/foo.swift:18:3: warning: case will never be executed
  case .boo(let bar, let bas):
  ^

I suspect that the first set comes from the Space Engine, and the second comes from SIL unreachable code diagnostics.

Metadata

Metadata

Assignees

Labels

SILGenArea → compiler: The SIL generation stagecompilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationpattern matchingFeature: pattern matchingstatementsFeature: statementsswift 5.3switchFeature → statements: 'switch' statementsswitch casesFeature → statements → switch: 'switch' statement cases

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions