Skip to content

Unreachable case in two-level sealed hierarchy is not detected #4314

Closed
@smarter

Description

@smarter

Given the following code:

sealed trait Foo[A]
case class One[A]() extends Foo[A]
sealed abstract case class Bar[A]() extends Foo[A]
class Two() extends Bar[String]

object Test {
  def test(x: Foo[Int]) = x match {
    case One() =>
  }
}

The exhaustiveness checker is smart enough to not warn, because no instance of Bar is a subtype of Foo[Int].

However, if we add a case for Bar() like this:

sealed trait Foo[A]
case class One[A]() extends Foo[A]
sealed abstract case class Bar[A]() extends Foo[A]
class Two() extends Bar[String]

object Test {
  def test(x: Foo[Int]) = x match {
    case One() =>
    case Bar() =>
  }
}

We should get an unreachable code warning (and indeed, scalac produces one), but we don't.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions