Skip to content

Commit 0656438

Browse files
committed
Refine hashing of AnnotatedTypes
Since we are always comparing annotations in AnnotatedTypes with `eq`, they should always be hashed with identityHashCode.
1 parent 2cd9998 commit 0656438

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/core/Hashable.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ trait Hashable {
9090
protected final def doHash(bs: Binders, x1: Any, tp2: Type): Int =
9191
finishHash(bs, hashing.mix(hashSeed, x1.hashCode), 1, tp2)
9292

93+
protected final def doHash(bs: Binders, x1: Int, tp2: Type): Int =
94+
finishHash(bs, hashing.mix(hashSeed, x1), 1, tp2)
95+
9396
protected final def doHash(bs: Binders, tp1: Type, tp2: Type): Int =
9497
finishHash(bs, hashSeed, 0, tp1, tp2)
9598

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4698,8 +4698,10 @@ object Types {
46984698

46994699
// equals comes from case class; no matching override is needed
47004700

4701-
override def computeHash(bs: Binders): Int = doHash(bs, annot, parent)
4702-
override def hashIsStable: Boolean = parent.hashIsStable
4701+
override def computeHash(bs: Binders): Int =
4702+
doHash(bs, System.identityHashCode(annot), parent)
4703+
override def hashIsStable: Boolean =
4704+
parent.hashIsStable
47034705

47044706
override def eql(that: Type): Boolean = that match
47054707
case that: AnnotatedType => (parent eq that.parent) && (annot eq that.annot)

0 commit comments

Comments
 (0)