Skip to content

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

Closed
@Lasering

Description

@Lasering

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions