Skip to content

Commit 1244a29

Browse files
committed
Use correct stat context when transforming Block
1 parent df045ea commit 1244a29

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ class TreeMapWithImplicits extends tpd.TreeMapWithPreciseStatContexts {
4848
override def transform(tree: Tree)(using Context): Tree = {
4949
try tree match {
5050
case Block(stats, expr) =>
51-
inContext(nestedScopeCtx(stats)) {
52-
if stats.exists(_.isInstanceOf[Import]) then
53-
// need to transform stats and expr together to account for import visibility
54-
val stats1 = transformStats(stats :+ expr, ctx.owner)
55-
cpy.Block(tree)(stats1.init, stats1.last)
56-
else super.transform(tree)
57-
}
51+
super.transform(tree)(using nestedScopeCtx(stats))
5852
case tree: DefDef =>
5953
inContext(localCtx(tree)) {
6054
cpy.DefDef(tree)(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,8 @@ object Trees {
14001400
case Assign(lhs, rhs) =>
14011401
cpy.Assign(tree)(transform(lhs), transform(rhs))
14021402
case Block(stats, expr) =>
1403-
cpy.Block(tree)(transformStats(stats, ctx.owner), transform(expr))
1403+
val stats1 = transformStats(stats :+ expr, ctx.owner)
1404+
cpy.Block(tree)(stats1.init, stats1.last)
14041405
case If(cond, thenp, elsep) =>
14051406
cpy.If(tree)(transform(cond), transform(thenp), transform(elsep))
14061407
case Closure(env, meth, tpt) =>

compiler/src/dotty/tools/dotc/transform/MegaPhase.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase {
296296
}
297297
case tree: Block =>
298298
inContext(prepBlock(tree, start)(using outerCtx)) {
299-
val stats = transformStats(tree.stats, ctx.owner, start)
300-
val expr = transformTree(tree.expr, start)
301-
goBlock(cpy.Block(tree)(stats, expr), start)
299+
val stats1 = transformStats(tree.stats :+ tree.expr, ctx.owner, start)
300+
goBlock(cpy.Block(tree)(stats1.init, stats1.last), start)
302301
}
303302
case tree: TypeApply =>
304303
inContext(prepTypeApply(tree, start)(using outerCtx)) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.nio.file.FileSystems
2+
import java.util.ArrayList
3+
4+
def directorySeparator: String =
5+
import scala.language.unsafeNulls
6+
FileSystems.getDefault().getSeparator()
7+
8+
def getFirstOfFirst(xs: ArrayList[ArrayList[ArrayList[String]]]): String =
9+
import scala.language.unsafeNulls
10+
xs.get(0).get(0).get(0)

0 commit comments

Comments
 (0)