Skip to content

Commit 8439c7f

Browse files
committed
FirstTransform: simplify needsCompanion code
1 parent 910481a commit 8439c7f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
3434

3535
override def phaseName = "firstTransform"
3636

37-
private var needsCompanionPredicate: ClassSymbol => Boolean = null
37+
private var addCompanionPhases: List[NeedsCompanions] = _
38+
39+
def needsCompanion(cls: ClassSymbol)(implicit ctx: Context) =
40+
addCompanionPhases.exists(_.isCompanionNeeded(cls))
3841

3942
override def prepareForUnit(tree: tpd.Tree)(implicit ctx: Context): TreeTransform = {
40-
needsCompanionPredicate = ctx.phasePlan.flatMap(_.filter(x => x.isInstanceOf[NeedsCompanions])).
41-
foldLeft((x: ClassSymbol) => false)((pred, phase) => x => pred(x) || phase.asInstanceOf[NeedsCompanions].isCompanionNeeded(x))
43+
addCompanionPhases = ctx.phasePlan.flatMap(_ collect { case p: NeedsCompanions => p })
4244
this
4345
}
4446

@@ -90,7 +92,7 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
9092
}
9193

9294
def addMissingCompanions(stats: List[Tree]): List[Tree] = stats map {
93-
case stat: TypeDef if (singleClassDefs contains stat.name) && needsCompanionPredicate(stat.symbol.asClass) =>
95+
case stat: TypeDef if (singleClassDefs contains stat.name) && needsCompanion(stat.symbol.asClass) =>
9496
val objName = stat.name.toTermName
9597
val nameClash = stats.exists {
9698
case other: MemberDef =>

0 commit comments

Comments
 (0)