Skip to content

Commit fbad29b

Browse files
committed
FirstTransform: simplify needsCompanion code
1 parent e5ca61a commit fbad29b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
3636

3737
private var needsCompanionPredicate: ClassSymbol => Boolean = null
3838

39+
private var addCompanionPhases: List[NeedsCompanions] = _
40+
41+
def needsCompanion(cls: ClassSymbol)(implicit ctx: Context) =
42+
addCompanionPhases.exists(_.isCompanionNeeded(cls))
43+
3944
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))
45+
addCompanionPhases = ctx.phasePlan.flatMap(_ collect { case p: NeedsCompanions => p })
4246
this
4347
}
4448

0 commit comments

Comments
 (0)