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

conflicting instances with inheritance from case class #18552

Closed
SimonGuilloud opened this issue Sep 14, 2023 · 3 comments · Fixed by #20141
Closed

conflicting instances with inheritance from case class #18552

SimonGuilloud opened this issue Sep 14, 2023 · 3 comments · Fixed by #20141
Assignees
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug Spree Suitable for a future Spree
Milestone

Comments

@SimonGuilloud
Copy link

SimonGuilloud commented Sep 14, 2023

Compiler version

Tested with 3.2.1 and 3.3.1

Minimized code

trait A
trait B extends A

trait M[+T]

case class MA(id:Int) extends M[A]
class MB(id:Int)  extends MA(id) with M[B]

Output

illegal inheritance: class MB inherits conflicting instances of non-variant base trait M.

  Direct basetype: M[Playground.B]
  Basetype via case class MA: M[A]

Expectation

Compiles, or meaningful error message. If MA is not a case class, the code compiles. The base trait M is not non-variant.

@SimonGuilloud SimonGuilloud added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 14, 2023
@soronpo
Copy link
Contributor

soronpo commented Sep 14, 2023

Compiles successfully on 2.13

@mbovel mbovel added area:desugar Desugaring happens after parsing but before typing, see desugar.scala and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 18, 2023
@SimonGuilloud
Copy link
Author

I accidentally rediscovered the bug while forgetting it was reported already. Does someone have an idea of a workaround other than implementing manually all the functions of case classes?

@EugeneFlesselle
Copy link
Contributor

@SimonGuilloud not sure if it would be suitable for your use case, but you can do:

trait M:
  type T

case class MA(id:Int) extends M:
  type T <: A
class MB(id:Int) extends MA(id):
  type T <: B

EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Apr 10, 2024
Closes scala#18552 which was actually not an error, see:
https://github.com/scala/scala3/blob/73882c5b62b8cd96031ad975f7677949433a9f21/compiler/src/dotty/tools/dotc/typer/RefChecks.scala#L889-L893

Co-authored-by: Anna Herlihy <herlihyap@gmail.com>
Co-authored-by: Natsu Kagami <natsukagami@gmail.com>
EugeneFlesselle added a commit that referenced this issue Apr 10, 2024
Closes #18552 which was actually not an error, see:
https://github.com/scala/scala3/blob/73882c5b62b8cd96031ad975f7677949433a9f21/compiler/src/dotty/tools/dotc/typer/RefChecks.scala#L889-L893

---------

Co-authored-by: Anna Herlihy <herlihyap@gmail.com>
Co-authored-by: Natsu Kagami <natsukagami@gmail.com>
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
WojciechMazur added a commit that referenced this issue Jul 5, 2024
Closes #18552 which was actually not an error, see:
https://github.com/scala/scala3/blob/73882c5b62b8cd96031ad975f7677949433a9f21/compiler/src/dotty/tools/dotc/typer/RefChecks.scala#L889-L893

---------

Co-authored-by: Anna Herlihy <herlihyap@gmail.com>
Co-authored-by: Natsu Kagami <natsukagami@gmail.com>
[Cherry-picked ed9fecc][modified]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants