Open
Description
Compiler version
3.2.1
Minimized code
Welcome to Scala 3.2.1 (19, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> object X { def unapplySeq(ns: List[Int]): Option[(Int, Seq[Int])] = Some((ns.head, ns.tail)) }
// defined object X
scala> List(1,2,3,4) match { case X(h, t*) => t case _ => Nil }
val res0: Seq[Int] = List(2, 3, 4)
scala> List(1,2,3,4) match { case X(h, m, t*) => t case _ => Nil }
val res1: Seq[Int] = List(3, 4)
Output
It allows more extracted elements than seems to be defined on the extractor.
This is not allowed on construction:
scala> List(1, 2, List(3, 4): _*)
^
error: Sequence argument type annotation `: _*` cannot be used here:
it is not the only argument to be passed to the single repeated parameter Int*
Expectation
➜ ~ scala -Xlint:stars-align
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 19).
Type in expressions for evaluation. Or try :help.
scala> object X { def unapplySeq(ns: List[Int]): Option[(Int, Seq[Int])] = Some((ns.head, ns.tail)) }
object X
scala> List(1,2,3,4) match { case X(h, m, t @ _*) => (m, t) case _ => (0, Nil) }
^
warning: Sequence wildcard (_*) does not align with repeated case parameter or extracted sequence; the result may be unexpected.
val res0: (Int, Seq[Int]) = (2,List(3, 4))