@@ -173,6 +173,19 @@ class ReifyQuotes extends MacroTransform {
173
173
case _ =>
174
174
}
175
175
176
+ /** Does the level of `sym` match the current level?
177
+ * An exception is made for inline vals in macros. These are also OK if their level
178
+ * is one higher than the current level, because on execution such values
179
+ * are constant expression trees and we can pull out the constant from the tree.
180
+ */
181
+ def levelOK (sym : Symbol )(implicit ctx : Context ): Boolean = levelOf.get(sym) match {
182
+ case Some (l) =>
183
+ l == level ||
184
+ sym.is(Inline ) && sym.owner.is(Macro ) && sym.info.isValueType && l - 1 == level
185
+ case None =>
186
+ true
187
+ }
188
+
176
189
/** Issue a "splice outside quote" error unless we ar in the body of an inline method */
177
190
def spliceOutsideQuotes (pos : Position )(implicit ctx : Context ) =
178
191
ctx.error(i " splice outside quotes " , pos)
@@ -188,7 +201,7 @@ class ReifyQuotes extends MacroTransform {
188
201
else i " ${sym.name}.this "
189
202
if (! isThis && sym.maybeOwner.isType)
190
203
check(sym.owner, sym.owner.thisType, pos)
191
- else if (sym.exists && ! sym.isStaticOwner && levelOf.getOrElse (sym, level) != level )
204
+ else if (sym.exists && ! sym.isStaticOwner && ! levelOK (sym) )
192
205
tp match {
193
206
case tp : TypeRef =>
194
207
importedTypes += tp
@@ -329,7 +342,7 @@ class ReifyQuotes extends MacroTransform {
329
342
cpy.Select (expansion)(cpy.Inlined (tree)(call, bindings, body), name)
330
343
case _ : Import =>
331
344
tree
332
- case tree : DefDef if tree.symbol.is(Macro ) =>
345
+ case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
333
346
val tree1 = nested(isQuote = true ).transform(tree)
334
347
// check macro code as it if appeared in a quoted context
335
348
cpy.DefDef (tree)(rhs = EmptyTree )
0 commit comments