File tree Expand file tree Collapse file tree 2 files changed +13
-27
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +13
-27
lines changed Original file line number Diff line number Diff line change @@ -70,11 +70,10 @@ object Splicer {
7070 def checkEscapedVariables (tree : Tree , expansionOwner : Symbol )(given ctx : Context ): tree.type =
7171 new TreeTraverser {
7272 private [this ] var locals = Set .empty[Symbol ]
73+ private def markSymbol (sym : Symbol )(implicit ctx : Context ): Unit =
74+ locals = locals + sym
7375 private def markDef (tree : Tree )(implicit ctx : Context ): Unit = tree match {
74- case tree : DefTree =>
75- val sym = tree.symbol
76- if (! locals.contains(sym))
77- locals = locals + sym
76+ case tree : DefTree => markSymbol(tree.symbol)
7877 case _ =>
7978 }
8079 def traverse (tree : Tree )(given ctx : Context ): Unit =
@@ -91,13 +90,7 @@ object Splicer {
9190 traverseOver(last)
9291 case CaseDef (pat, guard, body) =>
9392 val last = locals
94- // mark all bindings
95- new TreeTraverser {
96- def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
97- markDef(tree)
98- traverseChildren(tree)
99- }
100- }.traverse(pat)
93+ tpd.patVars(pat).foreach(markSymbol)
10194 traverseOver(last)
10295 case _ =>
10396 markDef(tree)
Original file line number Diff line number Diff line change @@ -47,14 +47,16 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
4747 /** Localy defined symbols seen so far by `StagingTransformer.transform` */
4848 protected def localSymbols : List [Symbol ] = enteredSyms
4949
50+ /** Enter staging level of symbol defined by `tree`, if applicable. */
51+ private def markSymbol (sym : Symbol )(implicit ctx : Context ): Unit =
52+ if ((sym.isClass || sym.maybeOwner.isTerm) && ! levelOfMap.contains(sym)) {
53+ levelOfMap(sym) = level
54+ enteredSyms = sym :: enteredSyms
55+ }
56+
5057 /** Enter staging level of symbol defined by `tree`, if applicable. */
5158 private def markDef (tree : Tree )(implicit ctx : Context ): Unit = tree match {
52- case tree : DefTree =>
53- val sym = tree.symbol
54- if ((sym.isClass || sym.maybeOwner.isTerm) && ! levelOfMap.contains(sym)) {
55- levelOfMap(sym) = level
56- enteredSyms = sym :: enteredSyms
57- }
59+ case tree : DefTree => markSymbol(tree.symbol)
5860 case _ =>
5961 }
6062
@@ -106,16 +108,7 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
106108
107109 case CaseDef (pat, guard, body) =>
108110 val last = enteredSyms
109- // mark all bindings
110- new TreeTraverser {
111- def traverse (tree : Tree )(implicit ctx : Context ): Unit = tree match {
112- case Quoted (t) => traverse(t)(quoteContext)
113- case Splice (t) => traverse(t)(spliceContext)
114- case _ =>
115- markDef(tree)
116- traverseChildren(tree)
117- }
118- }.traverse(pat)
111+ tpd.patVars(pat).foreach(markSymbol)
119112 mapOverTree(last)
120113
121114 case _ : Import =>
You can’t perform that action at this time.
0 commit comments