Skip to content

Commit 0ab2c1a

Browse files
committed
Collect imports in blocks
Fixes scala#11557
1 parent 90deb4f commit 0ab2c1a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ class TreeMapWithImplicits extends tpd.TreeMap {
6060
traverse(stats)
6161
}
6262

63-
private def nestedScopeCtx(defs: List[Tree])(using Context): Context = {
63+
private def nestedScopeCtx(stats: List[Tree])(using Context): Context = {
6464
val nestedCtx = ctx.fresh.setNewScope
65-
defs foreach {
65+
stats.foreach {
6666
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol)
6767
case _ =>
6868
}
69-
nestedCtx
69+
importScopeCtx(stats)(using nestedCtx)
7070
}
7171

7272
private def nestedPackageScopeCtx(tree: PackageDef)(using Context): Context =
73-
tree.stats.foldLeft(ctx.withOwner(tree.symbol)) {
73+
importScopeCtx(tree.stats)(using ctx.withOwner(tree.symbol))
74+
75+
private def importScopeCtx(stats: List[Tree])(using Context): Context =
76+
stats.foldLeft(ctx) {
7477
case (acc, stat: Import) => ctx.importContext(stat, stat.symbol)
7578
case (acc, _) => acc
7679
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
4646
/** The quotation level of the definition of the locally defined symbol */
4747
protected def levelOf(sym: Symbol): Int = levelOfMap.getOrElse(sym, 0)
4848

49-
/** Localy defined symbols seen so far by `StagingTransformer.transform` */
49+
/** Locally defined symbols seen so far by `StagingTransformer.transform` */
5050
protected def localSymbols: List[Symbol] = enteredSyms
5151

5252
/** If we are inside a quote or a splice */
@@ -74,7 +74,7 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
7474
/** Transform the expression splice `splice` which contains the spliced `body`. */
7575
protected def transformSplice(body: Tree, splice: Apply)(using Context): Tree
7676

77-
/** Transform the typee splice `splice` which contains the spliced `body`. */
77+
/** Transform the type splice `splice` which contains the spliced `body`. */
7878
protected def transformSpliceType(body: Tree, splice: Select)(using Context): Tree
7979

8080
override def transform(tree: Tree)(using Context): Tree =
@@ -109,7 +109,7 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
109109
try dropEmptyBlocks(quotedTree) match {
110110
case Spliced(t) =>
111111
// '{ $x } --> x
112-
// and adapt the refinment of `Quotes { type tasty: ... } ?=> Expr[T]`
112+
// and adapt the refinement of `Quotes { type reflect: ... } ?=> Expr[T]`
113113
transform(t).asInstance(tree.tpe)
114114
case _ => transformQuotation(quotedTree, tree)
115115
}

0 commit comments

Comments
 (0)