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

Fail to utilize HKT GADT bounds for applied types #13257

Closed
Linyxus opened this issue Aug 5, 2021 · 1 comment · Fixed by #13323
Closed

Fail to utilize HKT GADT bounds for applied types #13257

Linyxus opened this issue Aug 5, 2021 · 1 comment · Fixed by #13323
Assignees
Milestone

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Aug 5, 2021

Compiler version

3.0.1

Minimized code

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

Output

Found:    (0 : Int)
Required: F[A]

where:    F is a type in method foo which is an alias of [X] =>> Int

Expectation

By pattern matching we derive the GADT bound F := [X] =>> Int (as shown in the error message), but during type comparison the compiler will not recognize F[X] == Int for the applied type.

@Linyxus
Copy link
Contributor Author

Linyxus commented Aug 6, 2021

In the type comparison logic, only when both sides are HKTs will the GADT bounds for HKTs be used.

Actually a simple tweak will make the code compile:

type Const = [X] =>> Int
type Identity = [X] =>> X

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

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

If we are comparing A <:< F[X] and F has a lower bound G, it would be safe to downcast and turn to compare A <:< G[X]. Should we add the downcasting logic in the type comparer?

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.

3 participants