aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-30 21:49:56 +0200
committerMartin Odersky <odersky@gmail.com>2017-03-30 22:09:05 +0200
commitf801c835d8a1b359afe2f00aa270fe6e42923f2e (patch)
tree8e6f285c59621a47e307e004cd66b6c19000beb8 /compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala
parentf75caad00256db52bbd3310f245e51d23c2a76cc (diff)
downloaddotty-f801c835d8a1b359afe2f00aa270fe6e42923f2e.tar.gz
dotty-f801c835d8a1b359afe2f00aa270fe6e42923f2e.tar.bz2
dotty-f801c835d8a1b359afe2f00aa270fe6e42923f2e.zip
Make case class hashCode take class into account
Previously, elements of the following classes had the same hash code: case class A() case class B() Now they are distinguished.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala
index 9dfd92fe9..adf65c3bb 100644
--- a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala
+++ b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala
@@ -149,7 +149,7 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
* gets the hashCode method:
*
* def hashCode: Int = {
- * <synthetic> var acc: Int = 0xcafebabe;
+ * <synthetic> var acc: Int = productPrefix.hashCode()
* acc = Statics.mix(acc, x);
* acc = Statics.mix(acc, Statics.this.anyHash(y));
* Statics.finalizeHash(acc, 2)
@@ -157,7 +157,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(0xcafebabe)))
+ val accDef = ValDef(acc, This(clazz).select(defn.Product_productPrefix).select(defn.Any_hashCode).ensureApplied)
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)))