From aa2522c880d78d172b3af6cc4d336f2ebe447b18 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 31 Mar 2017 10:43:18 +0200 Subject: Use full name of case classes for hashing --- compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/transform') diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala index bb11348c2..13af7e112 100644 --- a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala @@ -144,12 +144,13 @@ class SyntheticMethods(thisTransformer: DenotTransformer) { /** The class * + * package p * case class C(x: T, y: T) * * gets the hashCode method: * * def hashCode: Int = { - * var acc: Int = "C".hashCode // constant folded + * var acc: Int = "p.C".hashCode // constant folded * acc = Statics.mix(acc, x); * acc = Statics.mix(acc, Statics.this.anyHash(y)); * Statics.finalizeHash(acc, 2) @@ -157,7 +158,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) { */ def caseHashCodeBody(implicit ctx: Context): Tree = { val acc = ctx.newSymbol(ctx.owner, "acc".toTermName, Mutable | Synthetic, defn.IntType, coord = ctx.owner.pos) - val accDef = ValDef(acc, Literal(Constant(clazz.name.toString.hashCode))) + val accDef = ValDef(acc, Literal(Constant(clazz.fullName.toString.hashCode))) val mixes = for (accessor <- accessors.toList) yield Assign(ref(acc), ref(defn.staticsMethod("mix")).appliedTo(ref(acc), hashImpl(accessor))) val finish = ref(defn.staticsMethod("finalizeHash")).appliedTo(ref(acc), Literal(Constant(accessors.size))) -- cgit v1.2.3