Skip to content

Commit aa2522c

Browse files
committed
Use full name of case classes for hashing
1 parent 6aba35f commit aa2522c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,21 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
144144

145145
/** The class
146146
*
147+
* package p
147148
* case class C(x: T, y: T)
148149
*
149150
* gets the hashCode method:
150151
*
151152
* def hashCode: Int = {
152-
* <synthetic> var acc: Int = "C".hashCode // constant folded
153+
* <synthetic> var acc: Int = "p.C".hashCode // constant folded
153154
* acc = Statics.mix(acc, x);
154155
* acc = Statics.mix(acc, Statics.this.anyHash(y));
155156
* Statics.finalizeHash(acc, 2)
156157
* }
157158
*/
158159
def caseHashCodeBody(implicit ctx: Context): Tree = {
159160
val acc = ctx.newSymbol(ctx.owner, "acc".toTermName, Mutable | Synthetic, defn.IntType, coord = ctx.owner.pos)
160-
val accDef = ValDef(acc, Literal(Constant(clazz.name.toString.hashCode)))
161+
val accDef = ValDef(acc, Literal(Constant(clazz.fullName.toString.hashCode)))
161162
val mixes = for (accessor <- accessors.toList) yield
162163
Assign(ref(acc), ref(defn.staticsMethod("mix")).appliedTo(ref(acc), hashImpl(accessor)))
163164
val finish = ref(defn.staticsMethod("finalizeHash")).appliedTo(ref(acc), Literal(Constant(accessors.size)))

0 commit comments

Comments
 (0)