Skip to content

Missing warning for unreachable case when matching on a tuple #12530

Closed
@smarter

Description

@smarter

Compiler version

Scala pre-3.0.1 at commit c1eaf8c

Minimized code

object Test {
  def foo(a: Boolean, b: Boolean): Unit =
    (a, b) match {
      case (false, _) =>
      case (true,  _) =>
      case (_, false) => // unreachable
    }
}

Output

No warning

Expectation

Emit an unreachable case warning like Scala 2 does:

warning: unreachable code
      case (_, false) => // unreachable
                      ^

However, note that Scala 2 also fails to emit such a warning in a more complex example:

object Test {
  def foo(a: Option[Boolean], b: Boolean): Unit =
    (a, b) match {
      case (Some(false), _) =>
      case (Some(true), _) =>
      case (None, _) =>
      case (_, false) => // unreachable
    }
}

In Scala 3 the issue seems to be that tuples are not considered to be decomposable types, but I don't know if this is intentional to avoid a complexity blow up /cc @liufengyun

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions