Skip to content

GADT issue #5418

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
allanrenucci opened this issue Nov 9, 2018 · 2 comments
Closed

GADT issue #5418

allanrenucci opened this issue Nov 9, 2018 · 2 comments

Comments

@allanrenucci
Copy link
Contributor

Found in the 2.13 std lib:

class Test {
  class Tree[A]
  class TreeSet[A](tree: Tree[A])

  def fromOrderedKeys[A](xs: Iterator[A]): Tree[A] = ???

  def from[E](it: Iterable[E]): TreeSet[E] =
    it match {
      case r: Range =>
        val it = r.iterator
        new TreeSet[E](fromOrderedKeys(it))
    }
}
-- [E007] Type Mismatch Error: Test.scala:11:39 --------------------
11 |        new TreeSet[E](fromOrderedKeys(it))
   |                                       ^^
   |                                       found:    Iterator[Int](it)
   |                                       required: Iterator[E]
   |                                       
one error found
@allanrenucci
Copy link
Contributor Author

cc/ @AleksanderBG

allanrenucci added a commit to dotty-staging/scala that referenced this issue Nov 9, 2018
@odersky
Copy link
Contributor

odersky commented Nov 10, 2018

The problem is that instantiation of covariant GADTs is unsound. So we can't implement that in Dotty. A cast is needed here.

@odersky odersky closed this as completed Nov 10, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Nov 12, 2018
allanrenucci added a commit to dotty-staging/scala that referenced this issue Nov 12, 2018
odersky added a commit that referenced this issue Nov 20, 2018
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