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

Unification check in deriving is incorrect #13487

Closed
sugakandrey opened this issue Sep 7, 2021 · 3 comments · Fixed by #13489
Closed

Unification check in deriving is incorrect #13487

sugakandrey opened this issue Sep 7, 2021 · 3 comments · Fixed by #13489

Comments

@sugakandrey
Copy link

Compiler version

3.0.1

Minimized code

trait TC[F[_, _[_]]]
object TC {
  def derived[F[_, _[_]]]: TC[F] = ???
}

case class Foo[A](a: A) derives TC

Output

Missing type parameter for _ in subpart Foo[_] of inferred type ([_, _[_$3]] =>> Foo[_])

Expectation

Foo cannot be unified with the type argument of TC as kinds of A and _[_] are different.
Note, that if we change TC to TC[_[_], _], we will now get Foo cannot be unified with the type argument of TC, even though it should compile. Perhaps https://github.com/lampepfl/dotty/blob/b7d2a122555a6aa44cc7590852a80f12512c535e/compiler/src/dotty/tools/dotc/typer/Deriving.scala#L163 was meant to use takeRight instead of take?

@Kordyjan
Copy link
Contributor

Kordyjan commented Sep 8, 2021

I'm not sure I understand what you mean.

Note, that if we change TC to TC[[], _], we will now get Foo cannot be unified with the type argument of TC, even though it should compile.

This part is especially is not clear to me. Could you provide a sample that should compile with some explanation? I'm still convinced that in the case you described compilation should fail.

@sugakandrey
Copy link
Author

sugakandrey commented Sep 8, 2021

@Kordyjan

Of course compilation should fail, only for a correct reason. Currently, it wrongly passes preliminary checks for the same-kindness of overlapping type parameters, generates a member with a nonsensical type TC[[x, y[_] =>> Foo[y]] and only then fails to typecheck it.

https://github.com/lampepfl/dotty/blob/b7d2a122555a6aa44cc7590852a80f12512c535e/compiler/src/dotty/tools/dotc/typer/Deriving.scala#L111-L133

trait TC[F[_[_], _]]
object TC {
  def derived[F[_[_], _]]: TC[F] = ???
}

case class Foo[A](a: A) derives TC

This example fails to compile, even though it should, because kinds of A and _ are both Type. In this cases generated derived$TC member would have return type TC[[x[_], y] =>> Foo[y]].

@Kordyjan
Copy link
Contributor

Kordyjan commented Sep 8, 2021

Oh, I see it now! Thanks for the explanation. Both of these behaviors are indeed the result of an underlying bug.

Kordyjan added a commit to dotty-staging/dotty that referenced this issue Sep 8, 2021
Kordyjan added a commit that referenced this issue Sep 27, 2021
Fix #13487: Unification check in deriving is incorrect
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
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.

2 participants