@@ -49,7 +49,11 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
49
49
*/
50
50
def syntheticMethods (clazz : ClassSymbol )(implicit ctx : Context ): List [Tree ] = {
51
51
val clazzType = clazz.typeRef
52
- lazy val accessors = clazz.caseAccessors
52
+ lazy val accessors =
53
+ if (isDerivedValueClass(clazz))
54
+ clazz.termParamAccessors
55
+ else
56
+ clazz.caseAccessors
53
57
54
58
val symbolsToSynthesize : List [Symbol ] =
55
59
if (clazz.is(Case )) caseSymbols
@@ -72,7 +76,8 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
72
76
ref(defn.runtimeMethod(" _" + sym.name.toString)).appliedToArgs(This (clazz) :: vrefss.head)
73
77
74
78
def syntheticRHS (implicit ctx : Context ): List [List [Tree ]] => Tree = synthetic.name match {
75
- case nme.hashCode_ => vrefss => hashCodeBody
79
+ case nme.hashCode_ if isDerivedValueClass(clazz) => vrefss => valueHashCodeBody
80
+ case nme.hashCode_ => vrefss => caseHashCodeBody
76
81
case nme.toString_ => forwardToRuntime
77
82
case nme.equals_ => vrefss => equalsBody(vrefss.head.head)
78
83
case nme.canEqual_ => vrefss => canEqualBody(vrefss.head.head)
@@ -116,11 +121,24 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
116
121
}
117
122
}
118
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
+
119
137
/** The class
120
138
*
121
139
* case class C(x: T, y: T)
122
140
*
123
- * get the hashCode method:
141
+ * gets the hashCode method:
124
142
*
125
143
* def hashCode: Int = {
126
144
* <synthetic> var acc: Int = 0xcafebabe;
@@ -129,7 +147,7 @@ class SyntheticMethods extends MiniPhaseTransform with IdentityDenotTransformer
129
147
* Statics.finalizeHash(acc, 2)
130
148
* }
131
149
*/
132
- def hashCodeBody (implicit ctx : Context ): Tree = {
150
+ def caseHashCodeBody (implicit ctx : Context ): Tree = {
133
151
val acc = ctx.newSymbol(ctx.owner, " acc" .toTermName, Mutable | Synthetic , defn.IntType , coord = ctx.owner.pos)
134
152
val accDef = ValDef (acc, Literal (Constant (0xcafebabe )))
135
153
val mixes = for (accessor <- accessors.toList) yield
0 commit comments