-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Pattern matching should retain the singleton type of the scrutinee #8083
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
This is actually due to something else: Anonymous classes lose their member info (since selecting that info would in general require reflection, which we don't want to support by default anymore). There have been several discussions about this and a resolution that we should selectively re-enable propagating the member info for anonymous classes implementing a val t: Test2 { val a: anA.type; val b: anA.B } = new Test2 { val a: anA.type = anA; val b = new a.B } it compiles. It also compiles if I make
|
Interesting, thanks for having a look. So that's why it worked in Scala 2. However, I am still thinking the original should work in Dotty. That is, it would be nice if the following: val t: Test2 = new Test2 { val a = anA; val b = new a.B }
t match {
case Test2(u, v) =>
u: t.a.type
v: t.a.B
} would be equivalent to this: val t: Test2 = new Test2 { val a = anA; val b = new a.B }
t match {
case $t: (t.type & Test2) =>
val u: $t.a.type = $t.a
val v: $t.b.type = $t.b
u: t.a.type // works
v: t.a.B // works
} Perhaps more importantly, this version: t match {
case q @ Test2(u, v) =>
u: q.a.type
v: q.a.B
} should arguably work, since the object Test2 {
def unapply(that: Test2): Option[(that.a.type, that.a.B)] = Some((that.a, that.b))
} and it would be nice if it also retained the dependency between the two extracted variables without having to write an explicit |
minimized code
This works in Scala 2.13, but fails in Dotty:
Scastie: https://scastie.scala-lang.org/nLrm92OqQgaolCvmPsf4ZA
Compilation output
It will probably be needed for #8073.
The text was updated successfully, but these errors were encountered: