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

Member selection does not take GADT constraints into account #7044

Closed
wdanilo opened this issue Aug 14, 2019 · 3 comments · Fixed by #8728
Closed

Member selection does not take GADT constraints into account #7044

wdanilo opened this issue Aug 14, 2019 · 3 comments · Fixed by #8728

Comments

@wdanilo
Copy link

wdanilo commented Aug 14, 2019

minimized code

case class Seg[T](pat:Pat[T], body:T)

trait Pat[T]
object Pat {
  case class Expr()            extends Pat[Int]
  case class Opt[S](el:Pat[S]) extends Pat[Option[S]]
}
  
def test[T](s:Seg[T]):Int = s match {
  case Seg(Pat.Expr(),body)          => (body: Int) + 1
  case Seg(Pat.Opt(Pat.Expr()),body) => (body: Option[Int]).get
}

expectation

As a long-time Haskeller, I would expect the above code to compile without providing the explicit signatures (body: Int) and (body: Option[Int]). The compiler has enough information to know that (especially as it does not allow me to write any other signature there). Writing them by hand is cumbersome and breaks the beauty of GADTs. I feel this is a very serious GADTs limitation in Dotty. I know that in Scala 2.x it was worse and unsound, but what we see in Dotty is rather a partial solution, not a final one.

@bishabosha
Copy link
Member

bishabosha commented Aug 14, 2019

Hi thanks for reporting, this is very related to #6323, perhaps you could add your comments to it?

@smarter
Copy link
Member

smarter commented Aug 14, 2019

Yeah this is a duplicate of #6323

@abgruszecki
Copy link
Contributor

Opening in preference to #6323.

@abgruszecki abgruszecki reopened this Aug 15, 2019
@abgruszecki abgruszecki changed the title GADTs inference is very weak in Dotty Member selection does not take GADT constraints into account Aug 15, 2019
abgruszecki added a commit that referenced this issue May 12, 2020
Fix #7044: Approximate GADT bounds to avoid explicit type ascriptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants