Re: [scala-reflect] arguments get replaced with null in MethodMirror.apply when there are both implicit and non-implicit parameters
John Sullivan <[email protected]>
| Newsgroups | gmane.comp.lang.scala,gmane.spam.detected |
|---|---|
| Message-ID | <[email protected]> |
Sorry for noise, just wanted to follow up with link to created issue: https://issues.scala-lang.org/browse/SI-9102 Thanks! On Monday, January 19, 2015 at 3:03:52 PM UTC-5, John Sullivan wrote: > > Thanks som-snytt. I'll file a bug tomorrow if I don't hear anything > further. Best, John > > On Monday, January 19, 2015 at 11:35:22 AM UTC-5, som-snytt wrote: >> >> Your fix fixes it. It's the AnyVal that sends it down that code path. >> >> I bet they would appreciate a Jira issue. >> >> >> >> On Mon, Jan 19, 2015 at 7:20 AM, John Sullivan <[email protected]> >> wrote: >> >>> Good morning everyone and happy MLK day! >>> >>> I seem to have found a bug in scala-reflect - when invoking apply on a >>> MethodMirror, I end up getting a null where I have supplied a non-null >>> value. >>> >>> Here is some sample code. You can see I get a null where I should get a >>> B(7): >>> >>> object Test extends App { >>> object a { >>> case class B(i: Int) >>> implicit class C(val i: Int) extends AnyVal >>> case class D(b: B, c: C) >>> } >>> >>> import a._ >>> import scala.reflect.runtime.currentMirror >>> import scala.reflect.runtime.universe._ >>> >>> val tpe = typeOf[D] >>> val classSymbol: ClassSymbol = tpe.typeSymbol.asClass >>> val moduleSymbol: ModuleSymbol = classSymbol.companion.asModule >>> val moduleMirror: ModuleMirror = >>> currentMirror.reflectModule(moduleSymbol) >>> val moduleInstance: Any = moduleMirror.instance >>> val instanceMirror = currentMirror.reflect(moduleInstance) >>> val typeSignature = instanceMirror.symbol.typeSignature >>> val applyMethod = typeSignature.member(TermName("apply")).asMethod >>> val applyMirror = instanceMirror.reflectMethod(applyMethod) >>> val applyResult = applyMirror(B(7), new C(8)) >>> println(applyResult) >>> // output is D(null,Test$a$C@8) >>> // the null seems to be due to a fall-through at line 433 of >>> JavaMirrors.scala >>> } >>> >>> This seems to happen whenever I have a MethodMirror with both implicit >>> and non-implicit parameters. I am not familiar with this code at all, but >>> to me it seems like an "else args1(i) = arg" is missing just below line 433 >>> of JavaMirrors.scala. >>> >>> This test was run against Scala 2.11.5, but I got the same results >>> against 2.11.2, 2.11.3, and 2.11.4. I tried against 2.10 as well, but the >>> API has changed a lot and I would have had to refactor to get it to compile >>> there. >>> >>> If you like I can submit a bug report. >>> >>> Thanks! -John >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "scala-language" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.