@@ -8,6 +8,7 @@ import Symbols._
88import SymDenotations ._
99import Names ._
1010import NameOps ._
11+ import StdNames ._
1112import NameKinds ._
1213import Flags ._
1314import Annotations ._
@@ -132,16 +133,17 @@ class SymUtils(val self: Symbol) extends AnyVal {
132133
133134 /** If this symbol is an enum value or a named class, register it as a child
134135 * in all direct parent classes which are sealed.
135- * @param @late If true, register only inaccessible children (all others are already
136- * entered at this point).
137136 */
138- def registerIfChild (late : Boolean = false )(implicit ctx : Context ): Unit = {
137+ def registerIfChild ()(implicit ctx : Context ): Unit = {
139138 def register (child : Symbol , parent : Type ) = {
140139 val cls = parent.classSymbol
141- if (cls.is(Sealed ) && (! late || child.isInaccessibleChildOf(cls)))
142- cls.addAnnotation(Annotation .Child (child))
140+ if (cls.is(Sealed )) {
141+ if ((child.isInaccessibleChildOf(cls) || child.isAnonymousClass) && ! self.hasAnonymousChild)
142+ cls.addAnnotation(Annotation .Child (cls))
143+ else cls.addAnnotation(Annotation .Child (child))
144+ }
143145 }
144- if (self.isClass && ! self.isAnonymousClass )
146+ if (self.isClass && ! self.isEnumAnonymClass )
145147 self.asClass.classParents.foreach { parent =>
146148 val child = if (self.is(Module )) self.sourceModule else self
147149 register(child, parent)
@@ -150,6 +152,10 @@ class SymUtils(val self: Symbol) extends AnyVal {
150152 register(self, self.info)
151153 }
152154
155+ /** Does this symbol refer to anonymous classes synthesized by enum desugaring? */
156+ def isEnumAnonymClass (implicit ctx : Context ): Boolean =
157+ self.isAnonymousClass && (self.owner.name.eq(nme.DOLLAR_NEW ) || self.owner.is(CaseVal ))
158+
153159 /** Is this symbol defined locally (i.e. at some level owned by a term) and
154160 * defined in a different toplevel class than its supposed parent class `cls`?
155161 * Such children are not pickled, and have to be reconstituted manually.
@@ -163,6 +169,9 @@ class SymUtils(val self: Symbol) extends AnyVal {
163169 case Annotation .Child (child) => child
164170 }
165171
172+ def hasAnonymousChild (implicit ctx : Context ): Boolean =
173+ children.exists(_ `eq` self)
174+
166175 /** Is symbol directly or indirectly owned by a term symbol? */
167176 @ tailrec final def isLocal (implicit ctx : Context ): Boolean = {
168177 val owner = self.owner
0 commit comments