File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ class SyntheticMethods(thisPhase: DenotTransformer) {
110
110
case nme.name => _ => Literal (Constant (" Hello World" ))
111
111
case nme.ordinal => _ => Literal (Constant (0 ))
112
112
case nme.compareTo => vrefss => compareToBody(vrefss.head.head)
113
- case nme.getDeclaringClass => _ => Literal ( Constant ( null ))
113
+ case nme.getDeclaringClass => _ => getDeclaringClassBody
114
114
}
115
115
ctx.log(s " adding $synthetic to $clazz at ${ctx.phase}" )
116
116
DefDef (synthetic, syntheticRHS(ctx.withOwner(synthetic))).withSpan(ctx.owner.span.focus)
@@ -138,6 +138,21 @@ class SyntheticMethods(thisPhase: DenotTransformer) {
138
138
Apply (thisOrdinalCompareTo, otherOrdinalBoxed :: Nil )
139
139
}
140
140
141
+ /** An enum case `X` in
142
+ *
143
+ * ```
144
+ * enum Foo { case X }
145
+ * ```
146
+ *
147
+ * gets the `getDeclaringClass` method:
148
+ *
149
+ * ```
150
+ * def getDeclaringClass: Class[Foo] = Predef.classOf[Foo]
151
+ * ```
152
+ */
153
+ def getDeclaringClassBody : Tree =
154
+ Ident (defn.Predef_classOfR ).appliedToType(clazz.info.parents.head)
155
+
141
156
/** The class
142
157
*
143
158
* ```
You can’t perform that action at this time.
0 commit comments