You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scala>classA
defined classA
scala>classB {
|deffoo(x: A) =1| }
defined classB
scala>valcm= reflect.runtime.currentMirror
cm: reflect.runtime.universe.Mirror=JavaMirrorwith scala.tools.nsc.interpreter.IMain$TranslatingClassLoader@1f517997 of typeclass scala.tools.nsc.interpreter.IMain$TranslatingClassLoaderwith classpath <unknown>
scala>valu= cm.universe
u: reflect.runtime.universe.type= scala.reflect.runtime.JavaUniverse@44cdf872
scala>valim= cm.reflect(newB)
im: reflect.runtime.universe.InstanceMirror= scala.reflect.runtime.JavaMirrors$JavaMirror$JavaInstanceMirror@76ad962c
scala>valmethod= im.symbol.asType.nonPrivateMember(u.newTermName("foo")).asMethodSymbol
method: reflect.runtime.universe.MethodSymbol= method foo
scala> im.reflectMethod(method)
res0: reflect.runtime.universe.MethodMirror= scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror@40c84051
scala> res0(newA)
java.lang.ClassNotFoundException: no Javaclasscorresponding to object$iw found
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.scala$reflect$runtime$JavaMirrors$JavaMirror$$anonfun$$noClass$1(JavaMirrors.scala:905)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1$$anonfun$apply$3.apply(JavaMirrors.scala:917)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1$$anonfun$apply$3.apply(JavaMirrors.scala:917)
at scala.Option.getOrElse(Option.scala:120)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.apply(JavaMirrors.scala:917)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.apply(JavaMirrors.scala:904)
at scala.reflect.runtime.TwoWayCache.toJava(TwoWayCache.scala:36)
at scala.reflect.runtime.JavaMirrors$JavaMirror.classToJava(JavaMirrors.scala:904)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.apply(JavaMirrors.scala:914)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.apply(JavaMirrors.scala:904)
at scala.reflect.runtime.TwoWayCache.toJava(TwoWayCache.scala:36)
at scala.reflect.runtime.JavaMirrors$JavaMirror.classToJava(JavaMirrors.scala:904)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.apply(JavaMirrors.scala:914)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$classToJava$1.apply(JavaMirrors.scala:904)
at scala.reflect.runtime.TwoWayCache.toJava(TwoWayCache.scala:36)
at scala.reflect.runtime.JavaMirrors$JavaMirror.classToJava(JavaMirrors.scala:904)
at scala.reflect.runtime.JavaMirrors$JavaMirror.typeToJavaClass(JavaMirrors.scala:974)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1$$anonfun$21.apply(JavaMirrors.scala:943)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1$$anonfun$21.apply(JavaMirrors.scala:943)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:239)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:239)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:77)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:239)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1.apply(JavaMirrors.scala:943)
at scala.reflect.runtime.JavaMirrors$JavaMirror$$anonfun$methodToJava$1.apply(JavaMirrors.scala:941)
at scala.reflect.runtime.TwoWayCache.toJava(TwoWayCache.scala:36)
at scala.reflect.runtime.JavaMirrors$JavaMirror.methodToJava(JavaMirrors.scala:941)
at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror.jmeth$lzycompute(JavaMirrors.scala:179)
at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror.jmeth(JavaMirrors.scala:178)
at scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror.apply(JavaMirrors.scala:192)
at .<init>(<console>:15)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:736)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:991)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:579)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:610)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:574)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:742)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:787)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:699)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:563)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:570)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:573)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:864)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:819)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:819)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:819)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:79)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
The text was updated successfully, but these errors were encountered:
@dcsobral said:
Even though this issue has been closed, I'd like to point out something said on issue SI-4316, linked by #4023:
Paul Phillips added a comment - 13/Aug/11 7:58 PM
Don't hold me to too many details, but yes. It is the reverse which gets us elsewhere: reflection expects a class called foo$bar$baz$1 to be nested inside a class called foo$bar$baz, and with us that's not all that likely.
Grzegorz Kossakowski added a comment - 13/Aug/11 8:05 PM
I see. It's interesting, I thought InnerClasses attribute in a class servers exactly this purpose to provide information about nesting. If implementations decided to ignore their own invention and rely on strings then I'd be in favor of ignoring Java reflection entirely.
It's quite likely that we'll be in luxury situation of having native Scala reflection that we can point folks at.
Is Scala reflection making use of that InnerClasses attribute? Could it, to avoid this problem?
The text was updated successfully, but these errors were encountered: