diff --git a/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala b/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala index e52bf1064e4c..ae674c25dc3d 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala @@ -30,16 +30,10 @@ class TreeMapWithImplicits extends tpd.TreeMapWithPreciseStatContexts { private def patternScopeCtx(pattern: Tree)(using Context): Context = { val nestedCtx = ctx.fresh.setNewScope - new TreeTraverser { - def traverse(tree: Tree)(using Context): Unit = { - tree match { - case d: DefTree if d.symbol.isOneOf(GivenOrImplicitVal) => - nestedCtx.enter(d.symbol) - case _ => - } - traverseChildren(tree) - } - }.traverse(pattern) + pattern.foreachSubTree { + case d: DefTree if d.symbol.isOneOf(GivenOrImplicitVal) => nestedCtx.enter(d.symbol) + case _ => + } nestedCtx } diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 872dc7793ff4..20124e04abd4 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -963,29 +963,24 @@ class Inliner(val call: tpd.Tree)(using Context): bindingOfSym(binding.symbol) = binding } - val countRefs = new TreeTraverser { - override def traverse(t: Tree)(using Context) = { - def updateRefCount(sym: Symbol, inc: Int) = - for (x <- refCount.get(sym)) refCount(sym) = x + inc - def updateTermRefCounts(t: Tree) = - t.typeOpt.foreachPart { - case ref: TermRef => updateRefCount(ref.symbol, 2) // can't be inlined, so make sure refCount is at least 2 - case _ => - } - - t match { - case t: RefTree => - updateRefCount(t.symbol, 1) - updateTermRefCounts(t) - case _: New | _: TypeTree => - updateTermRefCounts(t) - case _ => - } - traverseChildren(t) + def updateRefCount(sym: Symbol, inc: Int) = + for (x <- refCount.get(sym)) refCount(sym) = x + inc + def updateTermRefCounts(tree: Tree) = + tree.typeOpt.foreachPart { + case ref: TermRef => updateRefCount(ref.symbol, 2) // can't be inlined, so make sure refCount is at least 2 + case _ => } - } - countRefs.traverse(tree) - for (binding <- bindings) countRefs.traverse(binding) + def countRefs(tree: Tree) = + tree.foreachSubTree { + case t: RefTree => + updateRefCount(t.symbol, 1) + updateTermRefCounts(t) + case t @ (_: New | _: TypeTree) => + updateTermRefCounts(t) + case _ => + } + countRefs(tree) + for (binding <- bindings) countRefs(binding) def retain(boundSym: Symbol) = { refCount.get(boundSym) match { diff --git a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala index 20bcba417a5e..43e2aae4c58c 100644 --- a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala @@ -275,9 +275,7 @@ object PickledQuotes { QuotesCache(pickled) = tree // Make sure trees and positions are fully loaded - new TreeTraverser { - def traverse(tree: Tree)(using Context): Unit = traverseChildren(tree) - }.traverse(tree) + tree.foreachSubTree(identity) quotePickling.println(i"**** unpickled quote\n$tree") diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index bff9310dee88..436721a6774b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -1193,15 +1193,11 @@ trait Checking { */ def checkNoForwardDependencies(vparams: List[ValDef])(using Context): Unit = vparams match { case vparam :: vparams1 => - val check = new TreeTraverser { - def traverse(tree: Tree)(using Context) = tree match { - case id: Ident if vparams.exists(_.symbol == id.symbol) => - report.error(em"illegal forward reference to method parameter", id.srcPos) - case _ => - traverseChildren(tree) - } + vparam.tpt.foreachSubTree { + case id: Ident if vparams.exists(_.symbol == id.symbol) => + report.error(em"illegal forward reference to method parameter", id.srcPos) + case _ => } - check.traverse(vparam.tpt) checkNoForwardDependencies(vparams1) case Nil => }