Skip to content

Commit e0ff75d

Browse files
committed
Properly map children of mapped classes
If sealed classes are mapped in TypeTreeMap or mapSymbols, their children have to be mapped accordingly.
1 parent c86fb4f commit e0ff75d

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,19 @@ object Symbols {
826826
copy.info = completer
827827
copy.denot match
828828
case cd: ClassDenotation =>
829-
cd.registeredCompanion = cd.unforcedRegisteredCompanion.subst(originals, copies)
829+
cd.registeredCompanion = original.registeredCompanion.subst(originals, copies)
830830
case _ =>
831831
}
832832

833833
copies.foreach(_.ensureCompleted()) // avoid memory leak
834+
835+
// Update Child annotations of classes encountered previously to new values
836+
// if some child is among the mapped symbols
837+
for orig <- ttmap1.substFrom do
838+
if orig.is(Sealed) && orig.children.exists(originals.contains) then
839+
val sealedCopy = orig.subst(ttmap1.substFrom, ttmap1.substTo)
840+
sealedCopy.annotations = sealedCopy.annotations.mapConserve(ttmap1.apply)
841+
834842
copies
835843
}
836844

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
10401040
else if (sym.is(ModuleClass) && sym.isPackageObject && sym.name.stripModuleClassSuffix == tpnme.PACKAGE)
10411041
nameString(sym.owner.name)
10421042
else if (sym.is(ModuleClass))
1043-
nameString(sym.name.stripModuleClassSuffix)
1043+
nameString(sym.name.stripModuleClassSuffix) + idString(sym)
10441044
else if (hasMeaninglessName(sym))
10451045
simpleNameString(sym.owner) + idString(sym)
10461046
else

compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
140140
val parentEnum = vdef.owner.companionClass
141141
val children = parentEnum.children.zipWithIndex
142142
val candidate: Option[Int] = children.collectFirst { case (child, idx) if child == vdef => idx }
143-
assert(candidate.isDefined, i"could not find child for $vdef")
143+
assert(candidate.isDefined, i"could not find child for $vdef in ${parentEnum.children}%, % of $parentEnum")
144144
Literal(Constant(candidate.get))
145145

146146
def toStringBody(vrefss: List[List[Tree]]): Tree =

tests/pos/i12508c.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def fun(a: Any, b: Any = 2): Any = ???
2+
3+
def test =
4+
fun(
5+
b = println(1),
6+
a = {
7+
enum Option[+X]:
8+
case Some(x: X)
9+
case None
10+
if ??? then Option.Some(1) else Option.None
11+
}
12+
)

0 commit comments

Comments
 (0)