Skip to content

Commit ae836e4

Browse files
committed
Fix scala#9069: Complete children of sealed classes early
Complete children of sealed classes or traits when the parent class is completed.
1 parent 0540e5e commit ae836e4

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,24 @@ class Namer { typer: Typer =>
12801280
}
12811281
}
12821282

1283+
def completeChildren() =
1284+
1285+
def completeChildrenIn(owner: Symbol) =
1286+
def maybeChild(c: Symbol) =
1287+
!owner.is(Package)
1288+
|| c.infoOrCompleter.isInstanceOf[ClassCompleter]
1289+
&& c.associatedFile == cls.associatedFile
1290+
for c <- owner.info.decls.toList if c.isClass && maybeChild(c) do
1291+
//println(i"possible child of $cls: $c")
1292+
c.ensureCompleted()
1293+
1294+
if cls.is(Sealed) then
1295+
//println(i"completing children of $cls in ${cls.owner}")
1296+
completeChildrenIn(cls.owner)
1297+
completeChildrenIn(cls.companionClass)
1298+
//println(i"completed children of $cls")
1299+
end completeChildren
1300+
12831301
completeConstructor(denot)
12841302
denot.info = tempInfo
12851303

@@ -1307,6 +1325,7 @@ class Namer { typer: Typer =>
13071325
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
13081326
if (cls.isNoInitsClass) cls.primaryConstructor.setFlag(StableRealizable)
13091327
processExports(localCtx)
1328+
completeChildren()
13101329
}
13111330
}
13121331

tests/pos/i9069/Test.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def Test =
2+
summon[deriving.Mirror.SumOf[Foo]]

tests/pos/i9069/Wrapper.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sealed trait Foo
2+
case class Bar(x: Int) extends Foo

0 commit comments

Comments
 (0)