Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lrytz opened this issue Aug 22, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@lrytz
Copy link
Member

lrytz commented Aug 22, 2018

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.

@lrytz lrytz added this to the 2.13.0-RC1 milestone Aug 22, 2018
@lrytz lrytz self-assigned this Aug 22, 2018
@lrytz
Copy link
Member Author

lrytz commented Aug 23, 2018

Test case added in scala/scala#7120, the neg test should get a better error message.

@szeiger
Copy link
Member

szeiger commented Sep 6, 2018

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.

@adriaanm
Copy link
Contributor

adriaanm commented Jan 8, 2019

Let's improve the error message in 2.13.1. This does not block RC1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants