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

GADT bounds are not precise enough #4075

Closed
Blaisorblade opened this issue Mar 5, 2018 · 2 comments
Closed

GADT bounds are not precise enough #4075

Blaisorblade opened this issue Mar 5, 2018 · 2 comments

Comments

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Mar 5, 2018

#1754 is fixed but the error in #3990 seems incorrect:

case class One[T](fst: T)

object Test {
  def bad[T](e: One[T]) = e match {
    case foo: One[a] =>
      val t: T = e.fst
      val nok: Nothing = t // should not compile
      val ok: a = t // does compile
  }
}

The nok line should not compile because T = a, as shown by the ok line, but the error claims that T >: a, which is true but incomplete and misleading:

7   |      val nok: Nothing = t // should not compile
    |                         ^
    |                  found:    T(t)
    |                  required: Nothing
    |
    |                  where:    T is a type in method bad with bounds >: a
@Blaisorblade Blaisorblade self-assigned this Mar 5, 2018
@Blaisorblade Blaisorblade changed the title Erroneous bound in GADT error message Erroneous/incomplete bound in GADT error message Mar 5, 2018
@smarter
Copy link
Member

smarter commented Mar 6, 2018

The problem is deeper than the error message I think, in the following code the return type of bla in inferred to be One[_ >: T] and not One[T]:

case class One[T](fst: T)

object Test {
  def bad[T](e: One[T]) = e match {
    case foo: One[a] =>
      foo
  }
}

@smarter smarter changed the title Erroneous/incomplete bound in GADT error message GADT bounds are not precise enough Mar 6, 2018
@smarter
Copy link
Member

smarter commented Mar 6, 2018

This has the same root cause as what I described in #4069 (comment), we end up with constraints a >:> T and T >:> a but we don't unify them, so a value of type One[a] becomes a value of type One[_ >: T] outside of the scope where a is defined.

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

3 participants