You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scala> object A { def unapplySeq(x: Int) = Some(collection.mutable.ArrayBuffer(1,2,3)) }
defined object A
scala> 1 match { case A(1, xs @ _*) => xs }
^
error: error during expansion of this match (this is a scalac bug).
The underlying error was: type mismatch;
found : scala.collection.mutable.ArrayBuffer[Int]
required: Seq[Int]
The reason here is that drop returns an ArrayBuffer. The interface for name-based pattern matching requires drop to return a scala.Seq.
The text was updated successfully, but these errors were encountered:
The reason here is that drop returns an ArrayBuffer
I was never a fan of expecting different result types with and without drop because it causes unnecessary restrictions as in the example above and creates unnecessary toSeq calls in many other cases. My preference is to add toSeq whenever the type is not statically known to be scala.Seq, with or without drop.
In 2.12 this works:
2.13 (with scala/scala#7068) gives a cryptic error message:
The reason here is that
drop
returns anArrayBuffer
. The interface for name-based pattern matching requiresdrop
to return ascala.Seq
.The text was updated successfully, but these errors were encountered: