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) {
110110 case nme.name => _ => Literal (Constant (" Hello World" ))
111111 case nme.ordinal => _ => Literal (Constant (0 ))
112112 case nme.compareTo => vrefss => compareToBody(vrefss.head.head)
113- case nme.getDeclaringClass => _ => Literal ( Constant ( null ))
113+ case nme.getDeclaringClass => _ => getDeclaringClassBody
114114 }
115115 ctx.log(s " adding $synthetic to $clazz at ${ctx.phase}" )
116116 DefDef (synthetic, syntheticRHS(ctx.withOwner(synthetic))).withSpan(ctx.owner.span.focus)
@@ -138,6 +138,21 @@ class SyntheticMethods(thisPhase: DenotTransformer) {
138138 Apply (thisOrdinalCompareTo, otherOrdinalBoxed :: Nil )
139139 }
140140
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+
141156 /** The class
142157 *
143158 * ```
You can’t perform that action at this time.
0 commit comments