Skip to content

Commit 4c3ecb5

Browse files
committed
Refine criterion when to complete children
1 parent e32ee70 commit 4c3ecb5

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ object Flags {
339339
val (_, DefaultMethod @ _, _) = newFlags(38, "<defaultmethod>")
340340

341341
/** Symbol is an enum class or enum case (if used with case) */
342-
val (Enum @ _, _, _) = newFlags(40, "enum")
342+
val (Enum @ _, EnumVal @ _, _) = newFlags(40, "enum")
343343

344344
/** An export forwarder */
345345
val (Exported @ _, _, _) = newFlags(41, "exported")
@@ -530,7 +530,7 @@ object Flags {
530530
val DeferredOrLazyOrMethod: FlagSet = Deferred | Lazy | Method
531531
val DeferredOrTermParamOrAccessor: FlagSet = Deferred | ParamAccessor | TermParam // term symbols without right-hand sides
532532
val DeferredOrTypeParam: FlagSet = Deferred | TypeParam // type symbols without right-hand sides
533-
val EnumValue: FlagSet = Enum | StableRealizable // A Scala enum value
533+
val EnumValue: FlagSet = Enum | StableRealizable // A Scala enum value
534534
val StableOrErased: FlagSet = Erased | StableRealizable // Assumed to be pure
535535
val ExtensionMethod: FlagSet = Extension | Method
536536
val FinalOrInline: FlagSet = Final | Inline

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,23 +1583,32 @@ object SymDenotations {
15831583
*/
15841584
def children(using Context): List[Symbol] =
15851585

1586-
def completeChildrenIn(owner: Symbol) =
1587-
def maybeChild(c: Symbol) =
1588-
!owner.is(Package)
1589-
|| c.infoOrCompleter.match
1590-
case _: SymbolLoaders.SecondCompleter => c.associatedFile == symbol.associatedFile
1591-
case _ => false
1586+
def completeChildrenIn(owner: Symbol)(using Context) =
1587+
// Possible children are: classes extending Scala classes and
1588+
// Scala or Java enum values that are defined in owner.
1589+
// If owner is a package, we complete only
1590+
// children that are defined in the same file as their parents.
1591+
def maybeChild(sym: Symbol) =
1592+
(sym.isClass && !this.is(JavaDefined) || sym.is(EnumVal))
1593+
&& !owner.is(Package)
1594+
|| sym.infoOrCompleter.match
1595+
case _: SymbolLoaders.SecondCompleter => sym.associatedFile == this.symbol.associatedFile
1596+
case _ => false
1597+
15921598
if owner.isClass then
1593-
for c <- owner.info.decls.toList if c.isClass && maybeChild(c) do
1599+
for c <- owner.info.decls.toList if maybeChild(c) do
15941600
c.ensureCompleted()
1601+
end completeChildrenIn
15951602

15961603
if is(Sealed) then
1597-
if !is(ChildrenQueried) && !ctx.isAfterTyper then
1598-
// During typer, make sure all visible children are completed, so that
1599-
// they show up in Child annotations. A class is visible if it is defined
1600-
// in the same scope as `cls` or in the companion object of `cls`.
1601-
completeChildrenIn(owner)
1602-
completeChildrenIn(companionClass)
1604+
if !is(ChildrenQueried) then
1605+
// Make sure all visible children are completed, so that
1606+
// they show up in Child annotations. A possible child is visible if it
1607+
// is defined in the same scope as `cls` or in the companion object of `cls`.
1608+
inContext(ctx.withPhase(ctx.typerPhase)) {
1609+
completeChildrenIn(owner)
1610+
completeChildrenIn(companionClass)
1611+
}
16031612
setFlag(ChildrenQueried)
16041613

16051614
annotations.collect { case Annotation.Child(child) => child }.reverse

0 commit comments

Comments
 (0)