Skip to content

Better handling of extractors in reachability check #2363

Closed
@liufengyun

Description

@liufengyun

Dotty reports that in the following, one case is not reachable. Extractors should be better handled to avoid such annoying warnings.

sealed trait Expr
class IntExpr extends Expr
class BooleanExpr extends Expr

object IntExpr {
  def unapply(expr: Expr): Option[IntExpr] = ???
}

object BooleanExpr {
  def unapply(expr: Expr): Option[BooleanExpr] = ???
}


class Test {
  def foo(x: List[Expr]): Int = x match {
    case IntExpr(_) :: xs => 1
    case BooleanExpr(_) :: xs => 1                              //   <==   unreachable
    case Nil => 2
  }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions