@@ -80,6 +80,8 @@ object Splicer {
80
80
/** Tree interpreter that evaluates the tree */
81
81
private class Interpreter (pos : SourcePosition , classLoader : ClassLoader )(implicit ctx : Context ) extends AbstractInterpreter {
82
82
83
+ def checking : Boolean = false
84
+
83
85
type Result = Object
84
86
85
87
/** Returns the interpreted result of interpreting the code a call to the symbol with default arguments.
@@ -277,6 +279,7 @@ object Splicer {
277
279
278
280
/** Tree interpreter that tests if tree can be interpreted */
279
281
private class CheckValidMacroBody (implicit ctx : Context ) extends AbstractInterpreter {
282
+ def checking : Boolean = true
280
283
281
284
type Result = Unit
282
285
@@ -312,6 +315,9 @@ object Splicer {
312
315
313
316
/** Abstract Tree interpreter that can interpret calls to static methods with quoted or inline arguments */
314
317
private abstract class AbstractInterpreter (implicit ctx : Context ) {
318
+
319
+ def checking : Boolean
320
+
315
321
type Env = Map [Name , Result ]
316
322
type Result
317
323
@@ -370,20 +376,10 @@ object Splicer {
370
376
371
377
// Interpret `foo(j = x, i = y)` which it is expanded to
372
378
// `val j$1 = x; val i$1 = y; foo(i = y, j = x)`
373
- case Block (stats, expr) =>
374
- var unexpected : Option [Result ] = None
375
- val newEnv = stats.foldLeft(env)((accEnv, stat) => stat match {
376
- case stat : ValDef if stat.symbol.is(Synthetic ) =>
377
- accEnv.updated(stat.name, interpretTree(stat.rhs)(accEnv))
378
- case stat =>
379
- if (unexpected.isEmpty)
380
- unexpected = Some (unexpectedTree(stat))
381
- accEnv
382
- })
383
- unexpected.getOrElse(interpretTree(expr)(newEnv))
379
+ case Block (stats, expr) => interpretBlock(stats, expr)
384
380
case NamedArg (_, arg) => interpretTree(arg)
385
381
386
- case Inlined (_, Nil , expansion) => interpretTree( expansion)
382
+ case Inlined (_, bindings , expansion) => interpretBlock(bindings, expansion)
387
383
388
384
case Typed (expr, _) =>
389
385
interpretTree(expr)
@@ -395,6 +391,19 @@ object Splicer {
395
391
unexpectedTree(tree)
396
392
}
397
393
394
+ private def interpretBlock (stats : List [Tree ], expr : Tree )(implicit env : Env ) = {
395
+ var unexpected : Option [Result ] = None
396
+ val newEnv = stats.foldLeft(env)((accEnv, stat) => stat match {
397
+ case stat : ValDef if stat.symbol.is(Synthetic ) || ! checking =>
398
+ accEnv.updated(stat.name, interpretTree(stat.rhs)(accEnv))
399
+ case stat =>
400
+ if (unexpected.isEmpty)
401
+ unexpected = Some (unexpectedTree(stat))
402
+ accEnv
403
+ })
404
+ unexpected.getOrElse(interpretTree(expr)(newEnv))
405
+ }
406
+
398
407
object Call {
399
408
def unapply (arg : Tree ): Option [(RefTree , List [Tree ])] = arg match {
400
409
case Select (Call (fn, args), nme.apply) if defn.isImplicitFunctionType(fn.tpe.widenDealias.finalResultType) =>
0 commit comments