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

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

Closed
scabug opened this issue Sep 20, 2012 · 9 comments
Closed

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

scabug opened this issue Sep 20, 2012 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 20, 2012

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)
@scabug
Copy link
Author

scabug commented Sep 20, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6411?orig=1
Reporter: @retronym
Affected Versions: 2.10.0
See #6336

@scabug
Copy link
Author

scabug commented Sep 20, 2012

@retronym said:
Residuals from #6336

@scabug
Copy link
Author

scabug commented Sep 20, 2012

@paulp said:
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)
  }
}

@scabug
Copy link
Author

scabug commented Oct 30, 2012

@xeno-by said:
That's not related to value classes as a language feature, but rather to the reflection runtime.

@scabug
Copy link
Author

scabug commented Dec 13, 2012

@adriaanm said:
(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.)

@scabug
Copy link
Author

scabug commented Jan 31, 2013

@xeno-by said:
scala/scala#2041

@scabug
Copy link
Author

scabug commented Jan 31, 2013

@xeno-by said:
(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)

@scabug
Copy link
Author

scabug commented Feb 4, 2013

@xeno-by said (edited on Feb 4, 2013 10:26:52 PM UTC):
Don't have time for this in 2.10.1. The pull request has almost got through the review, though.

@scabug
Copy link
Author

scabug commented Jan 24, 2014

@xeno-by said:
scala/scala#3409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants