Skip to content

Complementing irrefutable unapplySeq aren't recognized as exhaustive #12252

@martijnhoekstra

Description

@martijnhoekstra

reproduction steps

using any version of Scala

object SeqExtractor {
  def unapplySeq(x: Int): Some[List[Int]] = Some(List(1))
}

1 match {
 case SeqExtractor() => "zero"
 case SeqExtractor(_) => "one"
 case SeqExtractor(_, _, _*) => "two or more"
}

problem

SeqExtractor is irrefutable, and the three cases together are exhaustive, but we fail to recognize that.

note

Matching on List can work around that by matching on Cons or Nil exhaustively with

List(1) match {
case Nil => 0 // or List() due to rewrite
case head :: Nil => 1
case head :: second :: tail => 2
}

Spun out of #12240

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)patmat

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions