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
Methods on List compile but throw NoSuchMethodError when called from Java #7374
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7374?orig=1 |
@vigdorchik said: |
Donny Nadolny (dnadolny) said:
I have also reproduced it with 2.10.0, however it works correctly under 2.9.2. |
@SethTisue said:
|
@retronym said:
I bisected that (the old fashioned way, as the regression pre dates the archive of builds available to scalac-hash), and landed scala/scala@a0a045f5c0. That was just a library change (introduction of I've been poking around in this space recently to fix some problems with generic sigs and erasure of value classes, so I'll take a look at this one. |
@Blaisorblade said: |
@retronym said: trait TraversableLike[Repr] {
def tail: Repr = ???
}
trait MyTraversable[A] extends TraversableLike[Option[A]]
abstract class MyAbstractTraversable extends MyTraversable[String]
scala> classOf[MyAbstractTraversable].getMethod("tail")
res16: java.lang.reflect.Method = public java.lang.Object MyAbstractTraversable.tail()
scala> classOf[MyAbstractTraversable].getMethod("tail").toGenericString
res17: String = public scala.Option<java.lang.String> MyAbstractTraversable.tail() |
@retronym said (edited on Sep 22, 2013 10:44:53 AM UTC):
I think I finally understand Paul's assertion that "we need more bridges". Rather than making the weakening generic signature to meet the erasure to |
@paulp said: |
@retronym said: I actually got part of the way there to installing additional bridges in mixin: https://github.com/retronym/scala/compare/ticket/3452-rebased (please excuse the expasperated messaage-free commits at the end of the sequence!) but was lucky enough that a test (or the library) alerted me to a corner case that resulted from spreading responsibility for bridges across two phases. The root complexity is, as you point out, running mixin after erasure. Martin told me he's going to try it way earlier next time around, all the way back in extension methods. |
@retronym said: |
@paulp said: |
@retronym said: |
@retronym said: More details: |
There are several methods on List that will compile when called from Java, but fail at runtime with a NoSuchMethodError. For example:
All 3 of those methods will fail at runtime:
list().tail():
list().par()
list().init()
The runtime type of the list is scala.collection.immutable.$colon$colon. If you were to cast it to that type, then tail() will compile and run:
I found this when unit tests failed when calling tail() and tried out a few other methods to find par() and init(). I assume there are other methods that would fail like this, but I didn't see any pattern. For example, both
init()
andinits()
show up as methods onTraversableLike
, butinits()
works.The text was updated successfully, but these errors were encountered: