Skip to content

Improve user experience when unapplySeq doesn't conform to the expected "structural" type #11102

Open
@lrytz

Description

@lrytz

In 2.12 this works:

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 }
res3: Seq[Int] = ArrayBuffer(2, 3)

2.13 (with scala/scala#7068) gives a cryptic error message:

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions