Skip to content

3.1.3 regression: spurious unreachable warning #15522

Closed
@armanbilge

Description

@armanbilge

Compiler version

  • 3.1.3
  • 3.2.1-RC1-bin-20220623-5a8a61d-NIGHTLY

Minimized code

//> using scala "3.2.1-RC1-bin-20220623-5a8a61d-NIGHTLY"

sealed trait Coverage {
  import Coverage.{ Empty, Range }

  def (other: Coverage): Coverage =
    (this, other) match {
      case (Empty, _) => Empty
      case (_, Empty) => 
        println("unreachable")
        Empty
      case (Range(a, b), Range(aʹ, bʹ)) => Coverage(a max aʹ, b min bʹ)
    }
}

object Coverage {

  def apply(min: Double, max: Double): Coverage =
    if (min < max) new Range(min, max) {} else Empty

  case object Empty extends Coverage

  sealed abstract case class Range(min: Double, max: Double) extends Coverage
}

@main def main =
  Coverage(0, 1).(Coverage.Empty)

Output

$ scala-cli bug.scala 
Compiling project (Scala 3.2.1-RC1-bin-20220623-5a8a61d-NIGHTLY, JVM)
[warn] ./bug.scala:10:12: Unreachable case
[warn]       case (_, Empty) => 
[warn]            ^^^^^^^^^^
Compiled project (Scala 3.2.1-RC1-bin-20220623-5a8a61d-NIGHTLY, JVM)
unreachable

Expectation

This is a regression since 3.1.2.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions