Navigation Menu

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

arguments get replaced with null in MethodMirror.apply when there are both implicit and non-implicit parameters #9102

Closed
scabug opened this issue Jan 20, 2015 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jan 20, 2015

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):

// Test.scala
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 very familiar with this code, 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.

@scabug
Copy link
Author

scabug commented Jan 20, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9102?orig=1
Reporter: john sullivan (sullivan)
Affected Versions: 2.11.2, 2.11.3, 2.11.4

@scabug scabug closed this as completed Mar 24, 2015
@scabug
Copy link
Author

scabug commented Jun 19, 2015

@SethTisue said:
scala/scala#4378

@scabug scabug added this to the 2.11.7 milestone Apr 7, 2017
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