@@ -22,6 +22,9 @@ object DesugarEnums {
22
22
/** Attachment containing the number of enum cases and the smallest kind that was seen so far. */
23
23
val EnumCaseCount : Property .Key [(Int , DesugarEnums .CaseKind .Value )] = new Property .Key
24
24
25
+ /** Attachment marking an anonymous class as a singleton case. */
26
+ val SingletonCase : Property .StickyKey [Unit ] = new Property .StickyKey
27
+
25
28
/** The enumeration class that belongs to an enum case. This works no matter
26
29
* whether the case is still in the enum class or it has been transferred to the
27
30
* companion object.
@@ -115,13 +118,13 @@ object DesugarEnums {
115
118
val toStringDef =
116
119
DefDef (nme.toString_, Nil , Nil , TypeTree (), Ident (nme.name))
117
120
.withFlags(Override )
118
- def creator = New (Template (
121
+ val creator = New (Template (
119
122
constr = emptyConstructor,
120
123
parents = enumClassRef :: Nil ,
121
124
derived = Nil ,
122
125
self = EmptyValDef ,
123
126
body = List (enumTagDef, toStringDef) ++ registerCall
124
- ))
127
+ ).withAttachment( SingletonCase , ()) )
125
128
DefDef (nme.DOLLAR_NEW , Nil ,
126
129
List (List (param(nme.tag, defn.IntType ), param(nme.name, defn.StringType ))),
127
130
TypeTree (), creator).withFlags(Private | Synthetic )
@@ -264,6 +267,7 @@ object DesugarEnums {
264
267
.withFlags(Override )
265
268
val (tagMeth, scaffolding) = enumTagMeth(CaseKind .Object )
266
269
val impl1 = cpy.Template (impl)(body = List (tagMeth, toStringMeth) ++ registerCall)
270
+ .withAttachment(SingletonCase , ())
267
271
val vdef = ValDef (name, TypeTree (), New (impl1)).withMods(mods | Final )
268
272
flatTree(scaffolding ::: vdef :: Nil ).withSpan(span)
269
273
}
0 commit comments