Skip to content

Commit 1839369

Browse files
committed
Only remove synthetic companion objects
If the object was explicitly written, it might be referenced, even if it is empty.
1 parent 24ccb77 commit 1839369

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ object Flags {
606606
final val AbstractFinal = allOf(Abstract, Final)
607607
final val AbstractSealed = allOf(Abstract, Sealed)
608608
final val SyntheticArtifact = allOf(Synthetic, Artifact)
609+
final val SyntheticModule = allOf(Synthetic, Module)
609610
final val SyntheticTermParam = allOf(Synthetic, TermParam)
610611
final val SyntheticTypeParam = allOf(Synthetic, TypeParam)
611612
final val SyntheticCase = allOf(Synthetic, Case)

src/dotty/tools/dotc/transform/DropEmptyCompanions.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ class DropEmptyCompanions extends MiniPhase { thisTransform =>
2626

2727
/** Is `tree` an empty companion object? */
2828
private def isEmptyCompanion(tree: Tree)(implicit ctx: Context) = tree match {
29-
case TypeDef(_, impl: Template) =>
30-
tree.symbol.is(Module) &&
29+
case TypeDef(_, impl: Template) if
30+
tree.symbol.is(SyntheticModule) &&
3131
tree.symbol.companionClass.exists &&
32-
impl.body.forall(_.symbol.isPrimaryConstructor)
32+
impl.body.forall(_.symbol.isPrimaryConstructor) =>
33+
//println(i"removing ${tree.symbol}")
34+
true
3335
case _ =>
3436
false
3537
}

0 commit comments

Comments
 (0)