You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess it may be some problem in handling covariant types in extractors.
Atry
changed the title
+: extractor is not able to infer the return type for views
+: extractor is not able to infer the return type for a view
Dec 31, 2019
Atry
changed the title
+: extractor is not able to infer the return type for a view
+: extractor is not able to infer the return type for a SeqView
Dec 31, 2019
I believe dotc is correct here. This should not typecheck. If we analyze what should be the parameters of the +:unapply, we get
[Int, collection.View, collection.SeqView[Int]]
But these do not bounds-check:
-- [E057] Type Mismatch Error: i7879.scala:5:35 --------------------------------
5 | scala.+:.unapply[Int, collection.View, collection.SeqView[Int]] // error
| ^
|Type argument collection.View does not conform to upper bound [_] => scala.collection.Seq[?]
If we look at the code produced by nsc, it looks problematic:
[[syntax trees at end of typer]] // i7879.scala
package <empty> {
object Test extends scala.AnyRef {
def <init>(): Test.type = {
Test.super.<init>();
()
};
private[this] val head1: Int with A = (scala.collection.immutable.List.apply[Int](1).view: scala.collection.SeqView[Int] @unchecked) match {
case scala.`package`.+:.unapply[Int with A, [_]scala.collection.View[_] with CC[_], scala.collection.SeqOps[A,CC,C] with scala.collection.SeqView[Int]](<unapply-selector>) <unapply> ((head1 @ _), _) => head1
};
<stable> <accessor> def head1: Int with A = Test.this.head1;
<synthetic> <artifact> private[this] val x$1: Unit = (Test.this.head1: Int with A @unchecked) match {
case (_: Int) => ()
}
}
}
Note the unbound parameters A, CC and C in the type arguments to unapply. So, I think this worked only by accident before and should be rejected.
minimized code
When compiling with Dotty 0.21.0-RC1, it reports the following error:
expectation
It should compile without error as Scala 2.13 did.
The text was updated successfully, but these errors were encountered: