From aedb8db47338637430672b145cfc11e8d89441b9 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 9 Sep 2012 11:16:24 +0200 Subject: 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. --- test/files/run/t6331.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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((), ()) -- cgit v1.2.3