summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-28 14:35:50 +0000
committerPaul Phillips <paulp@improving.org>2010-02-28 14:35:50 +0000
commitba5dbbd44db2c23c7532cde13453c6a031afb6e5 (patch)
tree00fbae4846f215cf90efda508f924cb790537e31 /test
parent432e16ce906cb1f03aabe26c0e51674780f44625 (diff)
downloadscala-ba5dbbd44db2c23c7532cde13453c6a031afb6e5.tar.gz
scala-ba5dbbd44db2c23c7532cde13453c6a031afb6e5.tar.bz2
scala-ba5dbbd44db2c23c7532cde13453c6a031afb6e5.zip
Added ## method to Any as our scala hashCode me...
Added ## method to Any as our scala hashCode method which provides consistent answers for primitive types. And I'm sure we're all tired of new starrs, but it's hard to add a method to Any without one. This patch only brings ## into existence, but nothing calls it yet. // some true assertions scala> assert(5.5f.## == 5.5f.hashCode) scala> assert(5.0f.## != 5.0f.hashCode && 5.0f.## == 5L.##) No review. (Already reviewed by odersky.)
Diffstat (limited to 'test')
-rw-r--r--test/files/run/hashhash.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/files/run/hashhash.scala b/test/files/run/hashhash.scala
new file mode 100644
index 0000000000..4a34ab12e0
--- /dev/null
+++ b/test/files/run/hashhash.scala
@@ -0,0 +1,15 @@
+object Test
+{
+ class A { val x1 = this.## ; val x2 = super.## }
+ val myA = new A
+ assert(myA.x1 == myA.x2)
+
+ def confirmSame(x: Any) = assert(x.## == x.hashCode, "%s.## != %s.hashCode".format(x, x))
+ def confirmDifferent(x: Any) = assert(x.## != x.hashCode, "%s.## == %s.hashCode (but should not)".format(x, x))
+
+ def main(args: Array[String]): Unit = {
+ /** Just a little sanity check, not to be confused with a unit test. */
+ List(5, 5.5f, "abc", new AnyRef, new A, ()) foreach confirmSame
+ List(5.0f, 1.0d, -(5.0f), (-1.0d)) foreach confirmDifferent
+ }
+}