diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index c0917ac8fb2a..3240300d8f52 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -75,7 +75,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => } } - /** Reorder statements so that module classes always come after their companion classes, add missing companion classes */ + /** Reorder statements so that module classes always come after their companion classes */ private def reorderAndComplete(stats: List[Tree])(implicit ctx: Context): List[Tree] = { val moduleClassDefs, singleClassDefs = mutable.Map[Name, Tree]() @@ -108,39 +108,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => case Nil => revPrefix.reverse } - def registerCompanion(name: TermName, forClass: Symbol): TermSymbol = { - val (modul, mcCompanion, classCompanion) = newCompanion(name, forClass) - if (ctx.owner.isClass) modul.enteredAfter(thisPhase) - mcCompanion.enteredAfter(thisPhase) - classCompanion.enteredAfter(thisPhase) - modul - } - - def addMissingCompanions(stats: List[Tree]): List[Tree] = stats map { - case stat: TypeDef if (singleClassDefs contains stat.name) && needsCompanion(stat.symbol.asClass) => - val objName = stat.name.toTermName - val nameClash = stats.exists { - case other: MemberDef => - other.name == objName && other.symbol.info.isParameterless - case _ => - false - } - val uniqueName = if (nameClash) AvoidClashName(objName) else objName - Thicket(stat :: ModuleDef(registerCompanion(uniqueName, stat.symbol), Nil).trees) - case stat => stat - } - - addMissingCompanions(reorder(stats, Nil)) - } - - private def newCompanion(name: TermName, forClass: Symbol)(implicit ctx: Context) = { - val modul = ctx.newCompleteModuleSymbol(forClass.owner, name, Synthetic, Synthetic, - defn.ObjectType :: Nil, Scopes.newScope, assocFile = forClass.asClass.assocFile) - val mc = modul.moduleClass - - val mcComp = ctx.synthesizeCompanionMethod(nme.COMPANION_CLASS_METHOD, forClass, mc) - val classComp = ctx.synthesizeCompanionMethod(nme.COMPANION_MODULE_METHOD, mc, forClass) - (modul, mcComp, classComp) + reorder(stats, Nil) } /** elimiate self in Template */