diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-09-09 11:16:24 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-09-09 11:16:24 +0200 |
commit | aedb8db47338637430672b145cfc11e8d89441b9 (patch) | |
tree | 0c8cf898fe508a950e0206cd86d7ce892c791d9c /test/files/run/t6331.scala | |
parent | 815f60ff9c50d22a23fbc9d980570fb6941a7d71 (diff) | |
download | scala-aedb8db47338637430672b145cfc11e8d89441b9.tar.gz scala-aedb8db47338637430672b145cfc11e8d89441b9.tar.bz2 scala-aedb8db47338637430672b145cfc11e8d89441b9.zip |
Test for consistency of Constant#{equals, hashCode}.
For the examples I've constructed, they are consistent, but
I put this down to good luck, rather than good management.
The next commit will address this.
Diffstat (limited to 'test/files/run/t6331.scala')
-rw-r--r-- | test/files/run/t6331.scala | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/test/files/run/t6331.scala b/test/files/run/t6331.scala index e9ed96fad3..4e43a7686e 100644 --- a/test/files/run/t6331.scala +++ b/test/files/run/t6331.scala @@ -15,7 +15,9 @@ object Test extends DirectTest { import global._ def check(c1: Any, c2: Any): Unit = { - val equal = Constant(c1) == Constant(c2) + val const1 = Constant(c1) + val const2 = Constant(c2) + val equal = const1 == const2 def show(a: Any) = "" + a + (a match { case _: Byte => ".toByte" case _: Short => ".toShort" @@ -26,6 +28,12 @@ object Test extends DirectTest { }) val op = if (equal) "==" else "!=" println(f"${show(c1)}%12s $op ${show(c2)}") + + val hash1 = const1.hashCode + val hash2 = const2.hashCode + val hashesEqual = hash1 == hash2 + val hashBroken = equal && !hashesEqual + if (hashBroken) println(f"$hash1%12s != $hash2 // hash codes differ for equal objects!!") } check((), ()) |