summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2010-03-24 14:23:40 +0000
committerMartin Odersky <odersky@gmail.com>2010-03-24 14:23:40 +0000
commit98cb7ad7c444919916a6d882f41378ecde269a9b (patch)
tree5de553a28e7eec8e80ea5e9c7760d9657e77fae5 /src
parent172b58c99fbbcc32c79a27605e351da936e734f5 (diff)
downloadscala-98cb7ad7c444919916a6d882f41378ecde269a9b.tar.gz
scala-98cb7ad7c444919916a6d882f41378ecde269a9b.tar.bz2
scala-98cb7ad7c444919916a6d882f41378ecde269a9b.zip
Fixes problematic equality of En umeration values.
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/Predef.scala16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index 20d70edadf..01df1a49f2 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -55,6 +55,22 @@ object Predef extends LowPriorityImplicits {
@inline def locally[T](x: T): T = x
+ // hashcode -----------------------------------------------------------
+
+ @inline def hash(x: Any): Int =
+ if (x.isInstanceOf[Number]) runtime.BoxesRunTime.hashFromNumber(x.asInstanceOf[Number])
+ else x.hashCode
+
+ @inline def hash(x: Number): Int =
+ runtime.BoxesRunTime.hashFromNumber(x)
+
+ @inline def hash(x: java.lang.Long): Int = {
+ val iv = x.intValue
+ if (iv == x.longValue) iv else x.hashCode
+ }
+
+ @inline def hash(x: Int): Int = x
+
// errors and asserts -------------------------------------------------
def error(message: String): Nothing = throw new RuntimeException(message)