aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorDmitry Petrashko <dark@d-d.me>2017-04-03 10:58:39 +0200
committerGitHub <noreply@github.com>2017-04-03 10:58:39 +0200
commit5021c768ccd123e148291bdda28920dea5e85630 (patch)
tree0b74649247b705b58578c131b05eea2f6ca1bbd8 /compiler
parent23709efcd3dc26459bcdd810c8b0eaa90f40f32d (diff)
parent710e700b2285738bc0700ed548517efc1f368bb0 (diff)
downloaddotty-5021c768ccd123e148291bdda28920dea5e85630.tar.gz
dotty-5021c768ccd123e148291bdda28920dea5e85630.tar.bz2
dotty-5021c768ccd123e148291bdda28920dea5e85630.zip
Merge pull request #2159 from dotty-staging/fix-hashcode
Make case class hashCode take class into account
Diffstat (limited to 'compiler')
-rw-r--r--compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala5
1 files changed, 3 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..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)))