diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2017-04-05 07:13:03 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-05 07:13:03 +1000 |
commit | 18157b92a43b2ab12a856fe15eb9d00d1e1bc0c6 (patch) | |
tree | d658c723fa048bf55ac10144b15f7bbd2b0e75e4 | |
parent | 197bb9e64076aaa7f0815458044df700597f7331 (diff) | |
parent | d6f25c2501c2b6f13cde620d09b8b952d05588b7 (diff) | |
download | scala-18157b92a43b2ab12a856fe15eb9d00d1e1bc0c6.tar.gz scala-18157b92a43b2ab12a856fe15eb9d00d1e1bc0c6.tar.bz2 scala-18157b92a43b2ab12a856fe15eb9d00d1e1bc0c6.zip |
Merge pull request #5811 from milessabin/topic/implicitinfo-hashcode
Make ImplicitInfo hashCode consistent with equals.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 5 | ||||
-rw-r--r-- | test/junit/scala/tools/nsc/typechecker/Implicits.scala | 39 |
2 files changed, 43 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index bee2ae8e99..a7eab21942 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -255,7 +255,10 @@ trait Implicits { this.sym == that.sym case _ => false } - override def hashCode = name.## + pre.## + sym.## + override def hashCode = { + import scala.util.hashing.MurmurHash3._ + finalizeHash(mix(mix(productSeed, name.##), sym.##), 2) + } override def toString = ( if (tpeCache eq null) name + ": ?" else name + ": " + tpe diff --git a/test/junit/scala/tools/nsc/typechecker/Implicits.scala b/test/junit/scala/tools/nsc/typechecker/Implicits.scala new file mode 100644 index 0000000000..75f4e70827 --- /dev/null +++ b/test/junit/scala/tools/nsc/typechecker/Implicits.scala @@ -0,0 +1,39 @@ +package scala.tools.nsc +package typechecker + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.testing.BytecodeTesting + +@RunWith(classOf[JUnit4]) +class ImplicitsTests extends BytecodeTesting { + import compiler.global._, definitions._, analyzer._ + + @Test + def implicitInfoHashCode(): Unit = { + val run = new global.Run + + enteringPhase(run.typerPhase) { + val T0 = IntClass.tpeHK + val T1 = refinedType(List(T0), NoSymbol) + + assert(T0 =:= T1) + assert(T0 != T1) + assert(T0.hashCode != T1.hashCode) + + val I0 = new ImplicitInfo(TermName("dummy"), T0, NoSymbol) + val I1 = new ImplicitInfo(TermName("dummy"), T1, NoSymbol) + + assert(I0 == I1) + assert(I0.hashCode == I1.hashCode) + + val pHash = (TermName("dummy"), NoSymbol).hashCode + + assert(I0.hashCode == pHash) + assert(I1.hashCode == pHash) + } + } +} |