Created
November 15, 2010 22:05
-
-
Save bjartek/701039 to your computer and use it in GitHub Desktop.
why does this not work? runtime exception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import annotation.tailrec | |
object Input { | |
def main(args: Array[String]) { | |
println(askInput) | |
} | |
@tailrec | |
private def askInput: String = { | |
lazy val input = try readLine.toInt -1 catch {case _ => -1} | |
if(input > 5) | |
"Great!" | |
else | |
askInput | |
} | |
} | |
/* | |
"scalac Input.scala" works fine but then "scala Input" borks with this: | |
java.lang.VerifyError: (class: Input$, method: input$1 signature: (Lscala/runtime/IntRef;Lscala/runtime/VolatileIntRef;)I) Inconsistent stack height 0 != 1 | |
at Input.main(tailrec.scala) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
at java.lang.reflect.Method.invoke(Method.java:597) | |
at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:81) | |
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24) | |
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:86) | |
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:81) | |
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:86) | |
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:83) | |
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment