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
scala.util.Try.apply produces java.lang.ClassCastException #6306
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6306?orig=1 |
@som-snytt said: object Min {
def f[A](a: =>A) = println(a.toString)
def main(args: Array[String]) {
f((1).toString)
f((1).##)
}
}
[[syntax trees at end of uncurry]] // simple-byname.scala
package badbyname {
object Min extends Object {
def <init>(): badbyname.Min.type = {
Min.super.<init>();
()
};
def f[A >: Nothing <: Any](a: () => A): Unit = scala.this.Predef.println(a.apply().toString());
def main(args: Array[String]): Unit = {
Min.this.f[String](1.toString());
Min.this.f[Int](1.##())
}
}
} |
@Blaisorblade said: object Min {
//Don't work
def f[A](a: =>A) = println(a.toString)
def f1[A <: AnyVal](a: =>A) = println(a.toString)
def f2[A <: AnyRef](a: =>A) = println(a.toString)
def f2a[A <: String](a: =>A) = println(a.toString)
//Works
def f3[A](a: =>Seq[A]) = println(a.toString)
def main(args: Array[String]) {
f3(Seq(1))
f3(Seq())
f((1).toString)
f((1).##)
f1((1).##)
f2((1).toString)
f2a((1).toString)
}
} |
@jrudolph said: |
@jrudolph said: |
@jrudolph said: |
@retronym said: This seems to trigger a long latent bug in But I'm not sure yet what should go there instead. |
@retronym said: scala210 -nocompdaemon -e "def foo[A](a: => A) = a; foo(1.getClass())"
java.lang.ClassCastException: java.lang.Class cannot be cast to scala.Function0
at Main$$anon$1.<init>(scalacmd4632653116387645739.scala:1) |
@som-snytt said (edited on Sep 4, 2012 10:49:34 PM UTC): Kind of a "ceci n'est pas une pipe" moment. I read that in the middle of the night and stopped blinking for an indeterminate length of time. https://github.com/scala/scala/blob/v2.10.0-M7/src/reflect/scala/reflect/internal/TreeInfo.scala#L70
|
@Blaisorblade said: It does work on the testcase, but it seems overkill; I add a set named If this becomes a pull request, I'll add proper acknowledgments to everybody involved. |
@Blaisorblade said (edited on Sep 13, 2012 1:54:50 PM UTC): |
A weird runtime exception by Try.apply
$ scala-2.10.0-M7/bin/scala -e 'scala.util.Try(1.toString)'
java.lang.ClassCastException: java.lang.String cannot be cast to scala.Function0
at Main$$anon$1.(scalacmd5144416276510110047.scala:1)
at Main$.main(scalacmd5144416276510110047.scala:1)
at Main.main(scalacmd5144416276510110047.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:71)
....
Same error can be reproduced in repl and in real compiled application using Test.scala:
object Test {
def main(args: Array[String]) {
scala.util.Try(1.toString)
}
}
$ scala-2.10.0-M7/bin/scalac Test.scala
$ scala-2.10.0-M7/bin/scala Test
The text was updated successfully, but these errors were encountered: