Skip to content

False-positive unreachable case warning #19359

Closed
@arainko

Description

@arainko

Compiler version

3.3.1, 3.4.0-RC1-bin-20231223-938d405-NIGHTLY

Minimized code

//> using scala 3.3.1

sealed trait Plan[+E <: Plan.Error, +F[+e <: E] <: Plan.Fallible[e]]

object Plan {
  case class Upcast() extends Plan[Nothing, Nothing]
  case class BetweenProducts[+E <: Plan.Error, +F[+e <: E] <: Plan.Fallible[e]](fields: List[Plan[E, F]]) extends Plan[E, F]
  case class Error() extends Plan[Plan.Error, Nothing]
  case class Fallible[+E <: Plan.Error]() extends Plan[E, Plan.Fallible]
}

@main def main = {
  val erroneousNotFallible: Plan[Plan.Error, Nothing] = Plan.BetweenProducts(Nil)
  
  erroneousNotFallible match
    case Plan.Upcast() => println("not boom")
    case Plan.BetweenProducts(fields) => println("reachable after all")
    case Plan.Error() => println("not boom")
}

Output

Compiling project (Scala 3.3.1, JVM (11))
[warn] ./Repro.scala:17:10
[warn] Unreachable case
[warn]     case Plan.BetweenProducts(fields) => println("reachable after all")
[warn]          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compiled project (Scala 3.3.1, JVM (11))
reachable after all

Expectation

No unreachable case warning.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions