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

Seqless unapplySeq partially unapplied #9869

Closed
scabug opened this issue Jul 25, 2016 · 3 comments · Fixed by scala/scala#9715
Closed

Seqless unapplySeq partially unapplied #9869

scabug opened this issue Jul 25, 2016 · 3 comments · Fixed by scala/scala#9715
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jul 25, 2016

//An unapplySeq for extractor can offer Option[Seq[S]] or Option[(A, B, Seq[S])].

//Omitting the Seq:

scala> object X { def unapplySeq(v: Any) = Option((1, 2, 3)) }
defined object X

scala> val X(x, y, z) = null
<console>:12: error: too many patterns for object X offering (Int, Int): expected 2, found 3
       val X(x, y, z) = null
           ^

scala> val X(x, y) = null
x: Int = 1
y: Int = 2

scala> val X(x, y, _*) = null
<console>:14: error: Star pattern must correspond with varargs or unapplySeq
       val X(x, y, _*) = null
           ^

// the bug permits idiom for avoiding SI-6675
// since apparently no tupling for unapplySeq

scala> val X(x) = null
<console>:13: error: not enough patterns for object X offering (Int, Int): expected 2, found 1
       val X(x) = null
           ^
@scabug
Copy link
Author

scabug commented Jul 25, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9869?orig=1
Reporter: @som-snytt
Affected Versions: 2.12.0-M5
See #6675

@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@adriaanm adriaanm removed their assignment Sep 28, 2018
@som-snytt
Copy link

Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 17-ea).
Type in expressions for evaluation. Or try :help.

scala> object X { def unapplySeq(v: Any) = Option((1, 2, 3)) }
object X

scala> val X(x, y, z) = null
           ^
       error: too many patterns for object X offering (Int, Int): expected 2, found 3

scala> val X(x, y) = null
scala.MatchError: null
  ... 32 elided

but

scala> object X { def unapplySeq(v: Any) = Option((1, 2, 3)) }
// defined object X

scala> val X(x, y, z) = null
1 |val X(x, y, z) = null
  |    ^^^^^^^^^^
  |     Option[(Int, Int, Int)] is not a valid result type of an unapplySeq method of an extractor.
1 |val X(x, y, z) = null
  |^
  |Recursive value $1$ needs type

Confirmed the reported behavior for 2.12.13, it's not a milestone thing.

scala> val X(x, y) = null
x: Int = 1
y: Int = 2

@som-snytt
Copy link

Really just duplicates #9538

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

Successfully merging a pull request may close this issue.

4 participants