Skip to content

+: extractor is not able to infer the return type for a SeqView #7879

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

Closed
Atry opened this issue Dec 31, 2019 · 2 comments
Closed

+: extractor is not able to infer the return type for a SeqView #7879

Atry opened this issue Dec 31, 2019 · 2 comments
Assignees

Comments

@Atry
Copy link
Contributor

Atry commented Dec 31, 2019

minimized code

val head1 +: _ = List(1).view
val _: Int = head1

When compiling with Dotty 0.21.0-RC1, it reports the following error:

Found:    (head1 : Any)
Required: Int

expectation

It should compile without error as Scala 2.13 did.

@Atry Atry added the itype:bug label Dec 31, 2019
@Atry
Copy link
Contributor Author

Atry commented Dec 31, 2019

I guess it may be some problem in handling covariant types in extractors.

@Atry 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 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
@odersky odersky self-assigned this Jan 6, 2020
@odersky
Copy link
Contributor

odersky commented Jan 6, 2020

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.

@odersky odersky closed this as completed in f51b96a Jan 6, 2020
odersky added a commit that referenced this issue Jan 6, 2020
Fix #7879: Turn test case into neg test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants