@@ -76,7 +76,8 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
76
76
ref(defn.runtimeMethod(" _" + sym.name.toString)).appliedToArgs(This (clazz) :: vrefss.head)
77
77
78
78
def syntheticRHS (implicit ctx : Context ): List [List [Tree ]] => Tree = synthetic.name match {
79
- case nme.hashCode_ => vrefss => hashCodeBody
79
+ case nme.hashCode_ if isDerivedValueClass(clazz) => vrefss => valueHashCodeBody
80
+ case nme.hashCode_ => vrefss => caseHashCodeBody
80
81
case nme.toString_ => forwardToRuntime
81
82
case nme.equals_ => vrefss => equalsBody(vrefss.head.head)
82
83
case nme.canEqual_ => vrefss => canEqualBody(vrefss.head.head)
@@ -120,11 +121,24 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
120
121
}
121
122
}
122
123
124
+ /** The class
125
+ *
126
+ * class C(x: T) extends AnyVal
127
+ *
128
+ * gets the hashCode method:
129
+ *
130
+ * def hashCode: Int = x.hashCode()
131
+ */
132
+ def valueHashCodeBody (implicit ctx : Context ): Tree = {
133
+ assert(accessors.length == 1 )
134
+ ref(accessors.head).select(nme.hashCode_).ensureApplied
135
+ }
136
+
123
137
/** The class
124
138
*
125
139
* case class C(x: T, y: T)
126
140
*
127
- * get the hashCode method:
141
+ * gets the hashCode method:
128
142
*
129
143
* def hashCode: Int = {
130
144
* <synthetic> var acc: Int = 0xcafebabe;
@@ -133,7 +147,7 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
133
147
* Statics.finalizeHash(acc, 2)
134
148
* }
135
149
*/
136
- def hashCodeBody (implicit ctx : Context ): Tree = {
150
+ def caseHashCodeBody (implicit ctx : Context ): Tree = {
137
151
val acc = ctx.newSymbol(ctx.owner, " acc" .toTermName, Mutable | Synthetic , defn.IntType , coord = ctx.owner.pos)
138
152
val accDef = ValDef (acc, Literal (Constant (0xcafebabe )))
139
153
val mixes = for (accessor <- accessors.toList) yield
0 commit comments