@@ -15,9 +15,6 @@ import SymUtils._
15
15
import NameKinds .OuterSelectName
16
16
import scala .collection .mutable
17
17
18
- // TODO
19
- // adapt to Expr/Type when passing arguments to splices
20
-
21
18
/** Translates quoted terms and types to `unpickle` method calls.
22
19
* Checks that the phase consistency principle (PCP) holds.
23
20
*/
@@ -173,6 +170,19 @@ class ReifyQuotes extends MacroTransform {
173
170
case _ =>
174
171
}
175
172
173
+ /** Does the level of `sym` match the current level?
174
+ * An exception is made for inline vals in macros. These are also OK if their level
175
+ * is one higher than the current level, because on execution such values
176
+ * are constant expression trees and we can pull out the constant from the tree.
177
+ */
178
+ def levelOK (sym : Symbol )(implicit ctx : Context ): Boolean = levelOf.get(sym) match {
179
+ case Some (l) =>
180
+ l == level ||
181
+ sym.is(Inline ) && sym.owner.is(Macro ) && sym.info.isValueType && l - 1 == level
182
+ case None =>
183
+ true
184
+ }
185
+
176
186
/** Issue a "splice outside quote" error unless we ar in the body of an inline method */
177
187
def spliceOutsideQuotes (pos : Position )(implicit ctx : Context ) =
178
188
ctx.error(i " splice outside quotes " , pos)
@@ -188,7 +198,7 @@ class ReifyQuotes extends MacroTransform {
188
198
else i " ${sym.name}.this "
189
199
if (! isThis && sym.maybeOwner.isType)
190
200
check(sym.owner, sym.owner.thisType, pos)
191
- else if (sym.exists && ! sym.isStaticOwner && levelOf.getOrElse (sym, level) != level )
201
+ else if (sym.exists && ! sym.isStaticOwner && ! levelOK (sym) )
192
202
tp match {
193
203
case tp : TypeRef =>
194
204
importedTypes += tp
@@ -329,7 +339,8 @@ class ReifyQuotes extends MacroTransform {
329
339
cpy.Select (expansion)(cpy.Inlined (tree)(call, bindings, body), name)
330
340
case _ : Import =>
331
341
tree
332
- case tree : DefDef if tree.symbol.is(Macro ) =>
342
+ case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
343
+ markDef(tree)
333
344
val tree1 = nested(isQuote = true ).transform(tree)
334
345
// check macro code as it if appeared in a quoted context
335
346
cpy.DefDef (tree)(rhs = EmptyTree )
0 commit comments