[scala-reflect] arguments get replaced with null in MethodMirror.apply when there are both implicit and non-implicit parameters

58 views
Skip to first unread message

John Sullivan

unread,
Jan 19, 2015, 10:20:14 AM1/19/15
to scala-l...@googlegroups.com
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

Som Snytt

unread,
Jan 19, 2015, 11:35:22 AM1/19/15
to scala-l...@googlegroups.com
Your fix fixes it. It's the AnyVal that sends it down that code path.

I bet they would appreciate a Jira issue.



--
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 scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Sullivan

unread,
Jan 19, 2015, 3:03:52 PM1/19/15
to scala-l...@googlegroups.com
Thanks som-snytt. I'll file a bug tomorrow if I don't hear anything further. Best, John

John Sullivan

unread,
Jan 21, 2015, 4:47:30 PM1/21/15
to scala-l...@googlegroups.com
Sorry for noise, just wanted to follow up with link to created issue: https://issues.scala-lang.org/browse/SI-9102

Thanks!
Reply all
Reply to author
Forward
0 new messages