@@ -22,6 +22,9 @@ object DesugarEnums {
2222 /** Attachment containing the number of enum cases and the smallest kind that was seen so far. */
2323 val EnumCaseCount : Property .Key [(Int , DesugarEnums .CaseKind .Value )] = new Property .Key
2424
25+ /** Attachment marking an anonymous class as a singleton case. */
26+ val SingletonCase : Property .StickyKey [Unit ] = new Property .StickyKey
27+
2528 /** The enumeration class that belongs to an enum case. This works no matter
2629 * whether the case is still in the enum class or it has been transferred to the
2730 * companion object.
@@ -115,13 +118,13 @@ object DesugarEnums {
115118 val toStringDef =
116119 DefDef (nme.toString_, Nil , Nil , TypeTree (), Ident (nme.name))
117120 .withFlags(Override )
118- def creator = New (Template (
121+ val creator = New (Template (
119122 constr = emptyConstructor,
120123 parents = enumClassRef :: Nil ,
121124 derived = Nil ,
122125 self = EmptyValDef ,
123126 body = List (enumTagDef, toStringDef) ++ registerCall
124- ))
127+ ).withAttachment( SingletonCase , ()) )
125128 DefDef (nme.DOLLAR_NEW , Nil ,
126129 List (List (param(nme.tag, defn.IntType ), param(nme.name, defn.StringType ))),
127130 TypeTree (), creator).withFlags(Private | Synthetic )
@@ -264,6 +267,7 @@ object DesugarEnums {
264267 .withFlags(Override )
265268 val (tagMeth, scaffolding) = enumTagMeth(CaseKind .Object )
266269 val impl1 = cpy.Template (impl)(body = List (tagMeth, toStringMeth) ++ registerCall)
270+ .withAttachment(SingletonCase , ())
267271 val vdef = ValDef (name, TypeTree (), New (impl1)).withMods(mods | Final )
268272 flatTree(scaffolding ::: vdef :: Nil ).withSpan(span)
269273 }
0 commit comments