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

Derivation of Enums fails when user defined a case companion object #15101

Closed
Lasering opened this issue May 4, 2022 · 1 comment · Fixed by #14986
Closed

Derivation of Enums fails when user defined a case companion object #15101

Lasering opened this issue May 4, 2022 · 1 comment · Fixed by #14986

Comments

@Lasering
Copy link

Lasering commented May 4, 2022

Compiler version

3.0.0 onwards

Minimized code

trait Encoder[T]
object Encoder:
  def derived[T](using scala.deriving.Mirror.Of[T]): Encoder[T] = ???

case object Bar
enum Bar derives Encoder:
  case A, B

summon[Encoder[Bar]]

Output

[error] java.lang.ClassCastException: class example.Bar$ cannot be cast to class scala.deriving.Mirror$Sum (example.Bar$ is in unnamed module of loader sbt.internal.LayeredClassLoader @3e209f63; scala.deriving.Mirror$Sum is in unnamed module of loader sbt.internal.ScalaLibraryClassLoader @69bc5ee3)
[error] 	at example.Bar$.derived$Encoder(Hello.scala:8)
[error] 	at example.Hello$package$.main(Hello.scala:12)
[error] 	at example.main.main(Hello.scala:11)
[error] 	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
[error] 	at java.base/java.lang.reflect.Method.invoke(Method.java:577)

Expectation

Code should run.

Remarks

If object Bar is not a case object the code runs without any problem.

@Lasering Lasering added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 4, 2022
@bishabosha
Copy link
Member

thanks for opening, this should be fixed by #14986

@bishabosha bishabosha added area:typeclass-derivation and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 4, 2022
@bishabosha bishabosha self-assigned this May 4, 2022
bishabosha added a commit to dotty-staging/dotty that referenced this issue May 4, 2022
bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 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.

3 participants