Skip to content

Spurious "Unreachable case" warning in a match on an ADT #14807

Closed
@cb372

Description

@cb372

Compiler version

3.1.1

Minimized code

enum Foo:
  case One(value: String)
  case Two(value: Long, month: java.time.Month)

object Issue:

  def doSomething(foo: Foo): String = foo match {
    case Foo.One(x)    => s"1 $x"
    case Foo.Two(x, y) => s"2 $x $y"
  }

Output

[warn] ./patmatbug.scala:9:10: Unreachable case
[warn]     case Foo.Two(x, y) => s"2 $x $y"
[warn]          ^^^^^^^^^^^^^

Expectation

Compiles without warnings, like Scala 2.13.

Notes

Surprisingly, if I switch the lines around to make case Foo.Two(x, y) the very first case in the match, the warning goes away.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions