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

Better utilizing GADT bounds for HKTs #13323

Merged
merged 14 commits into from
Aug 31, 2021
Merged

Conversation

Linyxus
Copy link
Contributor

@Linyxus Linyxus commented Aug 18, 2021

This PR fixes #13257. Before this PR, the following code example could not compile:

type Const = [X] =>> Int

trait Expr[+F[_]]
case class ConstExpr() extends Expr[Const]

def foo[F[_], A](e: Expr[F]): F[A] = e match
  case _: ConstExpr => 0

It is sound to allow its compilation, since Int <: Const[A] <: F[A]. This PR changes the TypeComparer's behavior by trying to approximate the type constructor when GADT bounds is available. A global state is added to the TypeComparer to track whether HKT bounds have been used during type comparison, to properly handle the injectivity conditions.

@abgruszecki
Copy link
Contributor

@Linyxus #13380 was merged, you can proceed with this PR.

@Linyxus
Copy link
Contributor Author

Linyxus commented Aug 29, 2021

@abgruszecki Hey Alex, I have finished the modification. Also, I add some additional code to allow the LHS HKT to be approximated to its GADT upper bound.

@Linyxus Linyxus changed the title Better utilizing GADT lower bounds for HKTs Better utilizing GADT bounds for HKTs Aug 29, 2021
Copy link
Contributor

@abgruszecki abgruszecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the nitpick, the PR LGTM.

compiler/src/dotty/tools/dotc/core/TypeComparer.scala Outdated Show resolved Hide resolved
@abgruszecki abgruszecki merged commit f8dec07 into scala:master Aug 31, 2021
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail to utilize HKT GADT bounds for applied types
3 participants