Skip to content

Commit 1f62746

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

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
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/tpd.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11951195
* - imports are reflected in the contexts of subsequent statements
11961196
*/
11971197
class TreeMapWithPreciseStatContexts(cpy: TreeCopier = tpd.cpy) extends TreeMap(cpy):
1198+
override def transform(tree: Tree)(using Context): Tree = tree match
1199+
case Block(stats, expr) =>
1200+
val stats1 = transformStats(stats :+ expr, ctx.owner)
1201+
cpy.Block(tree)(stats1.init, stats1.last)
1202+
case _ =>
1203+
super.transform(tree)
1204+
11981205
override def transformStats(trees: List[Tree], exprOwner: Symbol)(using Context): List[Tree] =
11991206
trees.mapStatements(exprOwner, transform(_))
12001207

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)