Skip to content

Commit c27c1bc

Browse files
committed
Use same local contexts as in TreeMap
1 parent 1a11e40 commit c27c1bc

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ import scala.annotation.tailrec
1616
class TreeMapWithImplicits extends tpd.TreeMap {
1717
import tpd._
1818

19-
protected def localCtx(tree: Tree)(implicit ctx: Context): FreshContext = {
20-
val sym = tree.symbol
21-
val owner = if (sym is PackageVal) sym.moduleClass else sym
22-
ctx.fresh.setTree(tree).setOwner(owner)
23-
}
24-
2519
def transformSelf(vd: ValDef)(implicit ctx: Context): ValDef =
2620
cpy.ValDef(vd)(tpt = transform(vd.tpt))
2721

@@ -75,11 +69,13 @@ class TreeMapWithImplicits extends tpd.TreeMap {
7569
}
7670

7771
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
72+
def localCtx =
73+
if (tree.hasType && tree.symbol.exists) ctx.withOwner(tree.symbol) else ctx
7874
try tree match {
7975
case tree: Block =>
8076
super.transform(tree)(nestedScopeCtx(tree.stats))
8177
case tree: DefDef =>
82-
implicit val ctx1 = localCtx(tree)(ctx)
78+
implicit val ctx = localCtx
8379
cpy.DefDef(tree)(
8480
tree.name,
8581
transformSub(tree.tparams),
@@ -89,7 +85,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
8985
case EmptyValDef =>
9086
tree
9187
case _: PackageDef | _: MemberDef =>
92-
super.transform(tree)(localCtx(tree))
88+
super.transform(tree)(localCtx)
9389
case impl @ Template(constr, parents, self, _) =>
9490
cpy.Template(tree)(
9591
transformSub(constr),

0 commit comments

Comments
 (0)