@@ -35,23 +35,28 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
35
35
import TreeMapWithStages ._
36
36
37
37
/** A map from locally defined symbols to their definition quotation level */
38
- private val levelOfMap : mutable.HashMap [Symbol , Int ] = ictx.property(LevelOfKey ).get
38
+ private [ this ] val levelOfMap : mutable.HashMap [Symbol , Int ] = ictx.property(LevelOfKey ).get
39
39
40
40
/** A stack of entered symbols, to be unwound after scope exit */
41
- private var enteredSyms : List [Symbol ] = Nil
41
+ private [this ] var enteredSyms : List [Symbol ] = Nil
42
+
43
+ /** If we are inside a quote or a splice */
44
+ private [this ] var inQuoteOrSplice = false
42
45
43
46
/** The quotation level of the definition of the locally defined symbol */
44
- protected def levelOf (sym : Symbol ): Option [ Int ] = levelOfMap.get (sym)
47
+ protected def levelOf (sym : Symbol ): Int = levelOfMap.getOrElse (sym, 0 )
45
48
46
49
/** Localy defined symbols seen so far by `StagingTransformer.transform` */
47
50
protected def localSymbols : List [Symbol ] = enteredSyms
48
51
49
- /** Enter staging level of symbol defined by `tree`, if applicable. */
52
+ /** If we are inside a quote or a splice */
53
+ protected def isInQuoteOrSplice : Boolean = inQuoteOrSplice
54
+
55
+ /** Enter staging level of symbol defined by `tree` */
50
56
private def markSymbol (sym : Symbol )(implicit ctx : Context ): Unit =
51
- if ((sym.isClass || sym.maybeOwner.isTerm) && ! levelOfMap.contains(sym)) {
57
+ if level != 0 && ! levelOfMap.contains(sym) then
52
58
levelOfMap(sym) = level
53
59
enteredSyms = sym :: enteredSyms
54
- }
55
60
56
61
/** Enter staging level of symbol defined by `tree`, if applicable. */
57
62
private def markDef (tree : Tree )(implicit ctx : Context ): Unit = tree match {
@@ -89,19 +94,25 @@ abstract class TreeMapWithStages(@constructorOnly ictx: Context) extends TreeMap
89
94
tree match {
90
95
91
96
case Quoted (quotedTree) =>
92
- dropEmptyBlocks(quotedTree) match {
97
+ val old = inQuoteOrSplice
98
+ inQuoteOrSplice = true
99
+ try dropEmptyBlocks(quotedTree) match {
93
100
case Spliced (t) =>
94
101
// '{ $x } --> x
95
102
// and adapt the refinment of `QuoteContext { type tasty: ... } ?=> Expr[T]`
96
103
transform(t).asInstance(tree.tpe)
97
104
case _ => transformQuotation(quotedTree, tree)
98
105
}
106
+ finally inQuoteOrSplice = old
99
107
100
108
case tree @ Spliced (splicedTree) =>
101
- dropEmptyBlocks(splicedTree) match {
109
+ val old = inQuoteOrSplice
110
+ inQuoteOrSplice = true
111
+ try dropEmptyBlocks(splicedTree) match {
102
112
case Quoted (t) => transform(t) // ${ 'x } --> x
103
113
case _ => transformSplice(splicedTree, tree)
104
114
}
115
+ finally inQuoteOrSplice = old
105
116
106
117
case Block (stats, _) =>
107
118
val last = enteredSyms
0 commit comments