typelevel / shapeless-3

Generic programming for Scala
189 stars 22 forks source link

ClassCastException: class scala.None$ cannot be cast to class scala.Some #245

Open xuwei-k opened 2 weeks ago

xuwei-k commented 2 weeks ago

build.sbt

libraryDependencies += "org.typelevel" %% "shapeless3-deriving" % "3.4.3"

scalaVersion := "3.5.1"

Main.scala

package example

import scala.annotation.StaticAnnotation

class A(x: Int) extends StaticAnnotation

case class Foo(
    a1: Int,
    @A(2) a2: Int,
    @A(3) a3: Int,
    @A(4) a4: Int,
    @A(5) a5: Int,
    @A(6) a6: Int,
    @A(7) a7: Int,
    @A(8) a8: Int,
    @A(9) a9: Int,
    @A(10) a10: Int,
    @A(11) a11: Int,
    @A(12) a12: Int,
    @A(13) a13: Int,
    @A(14) a14: Int,
    @A(15) a15: Int,
    @A(16) a16: Int,
    @A(17) a17: Int,
    @A(18) a18: Int,
    @A(19) a19: Int,
    @A(20) a20: Int,
    @A(21) a21: Int,
    @A(22) a22: Int,
    @A(23) a23: Int,
    @A(24) a24: Int
)

object Main {
  def main(args: Array[String]): Unit = {
    val x: Some[A] = shapeless3.deriving.Annotations[A, Foo].apply().head
  }
}

sbt run

[error] java.lang.ClassCastException: class scala.None$ cannot be cast to class scala.Some (scala.None$ and scala.Some are in unnamed module of loader sbt.internal.ScalaLibraryClassLoader @68cb9ead)
[error]     at example.Main$.main(Main.scala:36)
[error]     at example.Main.main(Main.scala)
[error]     at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
[error]     at java.base/java.lang.reflect.Method.invoke(Method.java:580)