Scala Programming Language
  1. Scala Programming Language
  2. SI-6411

Reflection: cannot invoke a method that takes a value class parameter

    Details

      Description

      scala> class X[T](val i: T) extends AnyVal
      defined class X
      
      scala> object a { def y[T](x: X[T]) = x.i }
      defined module a
      
      scala> val cm = reflect.runtime.currentMirror
      cm: reflect.runtime.universe.Mirror = JavaMirror with scala.tools.nsc.interpreter.IMain$TranslatingClassLoader@4bcc946b of type class scala.tools.nsc.interpreter.IMain$TranslatingClassLoader with classpath [(memory)] and parent being scala.tools.nsc.util.ScalaClassLoader$URLClassLoader@642423ad of type class scala.tools.nsc.util.ScalaClassLoader$URLClassLoader with classpath [file:/Library/Java/JavaVirtualMachines/1.6.0_27-b07-395.jdk/Contents/Classes/classes.jar,file:/Library/Java/JavaVirtualMachines/1.6.0_27-b07-395.jdk/Contents/Classes/ui.jar,file:/Library/Java/JavaVirtualMachines/1.6.0_27-b07-395.jdk/Contents/Classes/jsse.jar,file:/Library/Java/JavaVirtualMachines/1.6.0_27-b07-395.jdk/Contents/Classes/jce.jar,file:/Library/Java/JavaVirtualMachines/1.6.0_27-b07-395.jdk/Contents/Class...
      scala> val moduleA = cm.reflect(a)
      moduleA: reflect.runtime.universe.InstanceMirror = instance mirror for a$@6ff64801
      
      scala> val methodY = moduleA.symbol.typeSignature.declarations.last.asMethod
      methodY: reflect.runtime.universe.MethodSymbol = method y
      
      scala> moduleA.reflectMethod(methodY)
      res10: reflect.runtime.universe.MethodMirror = method mirror for a.y[T](x: X[T]): T (bound to a$@6ff64801)
      
      scala> res10(new X(0))
      java.lang.NoClassDefFoundError: no Java class corresponding to ErasedValueType(X[T]) found
      	at scala.reflect.runtime.JavaMirrors$JavaMirror.typeToJavaClass(JavaMirrors.scala:1160)
      

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -

          Residuals from SI-6336

          Show
          Jason Zaugg added a comment - Residuals from SI-6336
          Hide
          Paul Phillips added a comment -

          Here it is in a more test-casey form.

          
          class X[T](val i: T) extends AnyVal
          
          object a {
            def y[T](x: X[T]) = x.i
          }
          
          object Test {
            def main(args: Array[String]) {
              val cm      = scala.reflect.runtime.currentMirror
              val moduleA = cm.reflect(a)
              val methodY = moduleA.symbol.typeSignature.declarations.last.asMethod
              val m       = moduleA.reflectMethod(methodY)
          
              m(new X(0))
              // java.lang.NoClassDefFoundError: no Java class corresponding to ErasedValueType(X[T]) found
              //   at scala.reflect.runtime.JavaMirrors$JavaMirror.typeToJavaClass(JavaMirrors.scala:1225)
              //   at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1$$anonfun$27.apply(JavaMirrors.scala:1192)
              //   at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1$$anonfun$27.apply(JavaMirrors.scala:1192)
            }
          }
          
          Show
          Paul Phillips added a comment - Here it is in a more test-casey form. class X[T](val i: T) extends AnyVal object a { def y[T](x: X[T]) = x.i } object Test { def main(args: Array[String]) { val cm = scala.reflect.runtime.currentMirror val moduleA = cm.reflect(a) val methodY = moduleA.symbol.typeSignature.declarations.last.asMethod val m = moduleA.reflectMethod(methodY) m(new X(0)) // java.lang.NoClassDefFoundError: no Java class corresponding to ErasedValueType(X[T]) found // at scala.reflect.runtime.JavaMirrors$JavaMirror.typeToJavaClass(JavaMirrors.scala:1225) // at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1$$anonfun$27.apply(JavaMirrors.scala:1192) // at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1$$anonfun$27.apply(JavaMirrors.scala:1192) } }
          Hide
          Eugene Burmako added a comment -

          That's not related to value classes as a language feature, but rather to the reflection runtime.

          Show
          Eugene Burmako added a comment - That's not related to value classes as a language feature, but rather to the reflection runtime.
          Hide
          Adriaan Moors added a comment -

          (Pushing reflection bugs to 2.11 to aid scheduling – as it's experimental in 2.10.x, it shouldn't influence 2.10's schedule. They may be fixed earlier, of course.)

          Show
          Adriaan Moors added a comment - (Pushing reflection bugs to 2.11 to aid scheduling – as it's experimental in 2.10.x, it shouldn't influence 2.10's schedule. They may be fixed earlier, of course.)
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/pull/2041
          Hide
          Eugene Burmako added a comment -

          (That's just a random bug that I fixed to bring my number of open pull requests to 10. Feel free to demote it back to 2.11.0 if necessary)

          Show
          Eugene Burmako added a comment - (That's just a random bug that I fixed to bring my number of open pull requests to 10. Feel free to demote it back to 2.11.0 if necessary)
          Hide
          Eugene Burmako added a comment - - edited

          Don't have time for this in 2.10.1. The pull request has almost got through the review, though.

          Show
          Eugene Burmako added a comment - - edited Don't have time for this in 2.10.1. The pull request has almost got through the review, though.
          Show
          Eugene Burmako added a comment - https://github.com/scala/scala/pull/3409

            People

            • Assignee:
              Eugene Burmako
              Reporter:
              Jason Zaugg
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development