Created
June 18, 2010 02:00
-
-
Save rossabaker/443103 to your computer and use it in GitHub Desktop.
Scala equality pitfall
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
scala> null == 42 | |
res0: Boolean = false | |
scala> (null:java.lang.Integer) == 42 | |
java.lang.NullPointerException | |
at scala.runtime.BoxesRunTime.equalsNumNum(Unknown Source) | |
at scala.runtime.BoxesRunTime.equalsNumObject(Unknown Source) | |
at .<init>(<console>:6) | |
at .<clinit>(<console>) | |
at RequestResult$.<init>(<console>:9) | |
at RequestResult$.<clinit>(<console>) | |
at RequestResult$scala_repl_result(<console>) | |
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.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) | |
at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun... |
It does some magic to allow different numeric types to be equal if they have the same value (for example., 5 == 5.0d). A lot of complexity comes with that magic, I think.
Arrays redesign with java interoperability and all that Manifest stuff is another point. Language gaining bit verbose with code not related to what you really want to do. Scala is loosing points and the chance to be the next big language. :(
I posted the equality problem to the Scala mailing list, and within a couple hours, a fix was committed. Hooray for Paul Phillips and the rest of the Scala dev team.
http://scala-programming-language.1934581.n4.nabble.com/and-equals-td2261488.html#a2262102
http://lampsvn.epfl.ch/trac/scala/changeset/22379/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thinks are becoming a bit sad. :(