-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Align with changes to name-based pattern matching in Scala 2.13.0-M5 #4984
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
Comments
Setting priority to blocker since this change is needed to compile and use 2.13 standard library. See the definition of |
@nicolasstucki was also looking in that area for other reasons? |
In particular, this currently does not compile with Dotty: object Array2 {
// def unapplySeq[T](x: Array[T]): UnapplySeqWrapper[T] = new UnapplySeqWrapper(x)
def unapply[T](x: Array[T]): UnapplySeqWrapper[T] = new UnapplySeqWrapper(x)
final class UnapplySeqWrapper[T](private val a: Array[T]) extends AnyVal {
def isEmpty: Boolean = false
def get: UnapplySeqWrapper[T] = this
def lengthCompare(len: Int): Int = a.lengthCompare(len)
def apply(i: Int): T = a(i)
def drop(n: Int): scala.Seq[T] = ???
// ArraySeq.unsafeWrapArray(a.drop(n)) // clones the array, also if n == 0
def toSeq: scala.Seq[T] = a.toSeq // clones the array
}
}
class Test {
def test(xs: Array[Int]): Int = xs match {
case Array2(x, y) => x + y
}
} -- [E007] Type Mismatch Error: Test.scala:71:29 --------------------
71 | case Array2(x, y) => x + y
| ^
| found: Any(y)
| required: String |
Can we really get rid of
Consider this example: class Person(val name: String, val children: Person*)
object Person {
def unapply(p: Person) = Some((p.name, p.children))
}
class Test {
def test(p: Person): Person = p match {
case Person(_, c1) => c1
}
} Here class Person(val name: String, val children: Person*)
object Person {
def unapply(p: Person): Some[(String, Seq[Person])] = Some((p.name, p.children))
}
class Test {
def test(p: Person): Person = p match {
case Person(_, c1) => c1
}
} -- [E007] Type Mismatch Error: Test.scala:84:26 --------------------
84 | case Person(_, c1) => c1
| ^^
| found: Seq[Person](c1)
| required: Person
|
|
This comment has been minimized.
This comment has been minimized.
|
I don't think annotations should affect the semantic of a program. We are also deprecating this different form of extractor, so no it's not unrelated.
This issue is about supporting the same forms of name based pattern matching as scalac whether it is via I currently don't see how we can express repeated argument for name based pattern matching without object Array2 {
def unapply[T](x: Array[T]): UnapplySeqWrapper[T] = new UnapplySeqWrapper(x)
class UnapplySeqWrapper[T](a: Array[T]) {
def isEmpty: Boolean = false
def get: UnapplySeqWrapper[T] = this
def lengthCompare(len: Int): Int = ...
def apply(i: Int): T = ...
def drop(n: Int): scala.Seq[T] = ...
}
}
def test(xs: Array[Int]): Int = xs match {
case Array2(x) => x
} Here the extractor is ambiguous. What's the extracted value |
@allanrenucci I tend to agree: Those seem good reasons against both #4024 and dropping But I see a bigger problem with renaming For both reasons, I'd implement |
(EDIT: This is an attempted meeting summary): We'd absolutely have to keep unapplySeq for 3.0 (for migration), so we can support the Scala 2.12 API. We agree that |
Note also that there's still time to change how 2.13 behaves with respect to unapply/unapplySeq before release. |
This is more efficient anyway. Java BigDecimal::divideAndRemainder only returns an array with two elements.
This is more efficient anyway. Java BigDecimal::divideAndRemainder only returns an array with two elements.
Fix #4984: support name-based unapplySeq
See scala/scala#7068. Tentatively assigning to @OlivierBlanvillain since he wrote the current spec for name-based pattern matching in Dotty.
The text was updated successfully, but these errors were encountered: