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

Reflective call failed to a function that has both a value class parameter and a call-by-name parameter #10647

Open
Atry opened this issue Dec 7, 2017 · 3 comments
Labels
backend byname bytecode erasure fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) minimized regression runtime crash valueclass
Milestone

Comments

@Atry
Copy link

Atry commented Dec 7, 2017

class MyLong(val value: Long) extends AnyVal

object MyLong {
  def main(arguments: Array[String]): Unit = {
    // Works on both Scala 2.11 and Scala 2.12
    val ok1: ((=> Int) => Unit) { def apply(a: => Int): Unit } = { a => }
    ok1(a = 1)
    
    // Works on both Scala 2.11 and Scala 2.12
    val ok2: (MyLong => Unit) { def apply(b: MyLong): Unit } = { b => }
    ok2(b = new MyLong(0L))

    // Works on Scala 2.11 but crashes on Scala 2.12
    val regression: ((=> Int, Long) => Unit) { def apply(a: => Int, b: Long): Unit } = { (a, b) => }
    regression(a = 1, b = 0L)

    // Crashes on both Scala 2.11 and Scala 2.12
    val error: ((=> Int, MyLong) => Unit) { def apply(a: => Int, b: MyLong): Unit } = { (a, b) => }
    error(a = 1, b = new MyLong(0L))
  }
}
$ scala -version
Scala code runner version 2.12.4 -- Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.
java.lang.NoSuchMethodException: Main$$$Lambda$138/977993101.apply(scala.Function0, long)
	at java.lang.Class.getMethod(Class.java:1786)
	at Main$.reflMethod$Method2(MyLong.scala:12)
	at Main$.main(MyLong.scala:12)
	at Main.main(MyLong.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at scala.reflect.internal.util.ScalaClassLoader.$anonfun$run$2(ScalaClassLoader.scala:99)
	at scala.reflect.internal.util.ScalaClassLoader.asContext(ScalaClassLoader.scala:34)
	at scala.reflect.internal.util.ScalaClassLoader.asContext$(ScalaClassLoader.scala:30)
	at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:125)
	at scala.reflect.internal.util.ScalaClassLoader.run(ScalaClassLoader.scala:99)
	at scala.reflect.internal.util.ScalaClassLoader.run$(ScalaClassLoader.scala:91)
	at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:125)
	at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:22)
	at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:21)
	at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39)
	at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:29)
	at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:28)
	at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39)
	at scala.tools.nsc.ScriptRunner.runCompiled(ScriptRunner.scala:173)
	at scala.tools.nsc.ScriptRunner.$anonfun$runScript$1(ScriptRunner.scala:190)
	at scala.tools.nsc.ScriptRunner.$anonfun$runScript$1$adapted(ScriptRunner.scala:190)
	at scala.tools.nsc.ScriptRunner.$anonfun$withCompiledScript$2(ScriptRunner.scala:159)
	at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:127)
	at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:203)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
	at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:85)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@Atry
Copy link
Author

Atry commented Dec 7, 2017

What's strange here is that either solo call-by-name parameter or solo value class parameter works well, but a function that accepts both the two parameters failed.

@Atry Atry changed the title Reflective call failed to functions that has both a value class parameter and a call-by-name parameter Reflective call failed to a function that has both a value class parameter and a call-by-name parameter Dec 7, 2017
@Atry Atry added the regression label Feb 7, 2018
@Atry
Copy link
Author

Atry commented Feb 7, 2018

Note that this bug has a regression variant.

When the function has both a built-in value class (e.g. Long) parameter and a call-by-name parameter, it works on Scala 2.11 but crashes on Scala 2.12.

@SethTisue SethTisue removed the crash label Feb 7, 2018
@Atry
Copy link
Author

Atry commented Feb 3, 2023

Fixed in Scala 3

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Feb 3, 2023
@SethTisue SethTisue added this to the Backlog milestone Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend byname bytecode erasure fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) minimized regression runtime crash valueclass
Projects
None yet
Development

No branches or pull requests

2 participants