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

Implicit view to covariant type does not compile #8378

Closed
scabug opened this issue Mar 8, 2014 · 2 comments
Closed

Implicit view to covariant type does not compile #8378

scabug opened this issue Mar 8, 2014 · 2 comments

Comments

@scabug
Copy link

scabug commented Mar 8, 2014

class ImplicitNotFound {

  def main(arguments: Array[String]) {
    {
      implicit def view[A: Manifest](a: Int): Array[A] = ???
      val array: Array[Int] = 1 // OK
    }

    {
      implicit def view[A: Manifest](a: Int): Seq[A] = ???
      val seq: Seq[Int] = view(1) // OK
    }

    {
      implicit def view[A: Manifest](a: Int): Seq[A] = ???
      val seq: Seq[Int] = 1 // type mismatch;  found   : Int(1)  required: Seq[Int]
    }
  }
}

I think this is a bug, because:

  • val seq: Seq[Int] = view(1) is valid.
  • view is implicit.
  • val seq: Seq[Int] = 1 should be converted to val seq: Seq[Int] = view(1), but it's not.

Workaround:

type InvariantSeq[A] = Seq[A]
implicit def view[A: Manifest](a: Int): InvariantSeq[A] = ???
val invariantSeq: InvariantSeq[Int] = 1 // OK
val seq: Seq[Int] = invariantSeq // OK
@scabug
Copy link
Author

scabug commented Mar 8, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8378?orig=1
Reporter: @Atry
Affected Versions: 2.10.3

@scabug
Copy link
Author

scabug commented Mar 10, 2014

@adriaanm said:
This compiles on 2.11.0-RC1, expanding to:

val seq: Seq[Int] = view[Nothing](1)(reflect.this.ManifestFactory.Nothing)

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

1 participant