diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala | 5 | ||||
-rw-r--r-- | tests/run/caseClassHash.check | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala index 9dfd92fe9..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 = { - * <synthetic> var acc: Int = 0xcafebabe; + * <synthetic> 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(0xcafebabe))) + 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))) diff --git a/tests/run/caseClassHash.check b/tests/run/caseClassHash.check index b5a6f08e9..332fd477d 100644 --- a/tests/run/caseClassHash.check +++ b/tests/run/caseClassHash.check @@ -1,9 +1,9 @@ Foo(true,-1,-1,d,-5,-10,500.0,500.0,List(),5.0) Foo(true,-1,-1,d,-5,-10,500.0,500.0,List(),5) -1383698062 -1383698062 +205963949 +205963949 true -## method 1: 1383698062 -## method 2: 1383698062 +## method 1: 205963949 +## method 2: 205963949 Murmur 1: 1383698062 Murmur 2: 1383698062 |