@@ -36,21 +36,10 @@ object Splicer {
36
36
val liftedArgs = getLiftedArgs(call, bindings)
37
37
val interpreter = new Interpreter (pos, classLoader)
38
38
val interpreted = interpreter.interpretCallToSymbol[Seq [Any ] => Object ](call.symbol)
39
- try {
39
+ evaluateMacro(pos) {
40
+ // Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree
40
41
val evaluated = interpreted.map(lambda => lambda(liftedArgs).asInstanceOf [scala.quoted.Expr [Nothing ]])
41
42
evaluated.fold(tree)(PickledQuotes .quotedExprToTree)
42
- } catch {
43
- case ex : scala.quoted.QuoteError =>
44
- ctx.error(ex.getMessage, pos)
45
- EmptyTree
46
- case NonFatal (ex) =>
47
- val msg =
48
- s """ Failed to evaluate inlined quote.
49
- | Caused by ${ex.getClass}: ${if (ex.getMessage == null ) " " else ex.getMessage}
50
- | ${ex.getStackTrace.takeWhile(_.getClassName != " dotty.tools.dotc.transform.Splicer$" ).init.mkString(" \n " )}
51
- """ .stripMargin
52
- ctx.error(msg, pos)
53
- EmptyTree
54
43
}
55
44
}
56
45
@@ -87,6 +76,24 @@ object Splicer {
87
76
liftArgs(call.symbol.info, allArgs(call, Nil ))
88
77
}
89
78
79
+ /* Evaluate the code in the macro and handle exceptions durring evaluation */
80
+ private def evaluateMacro (pos : Position )(code : => Tree )(implicit ctx : Context ): Tree = {
81
+ try code
82
+ catch {
83
+ case ex : scala.quoted.QuoteError =>
84
+ ctx.error(ex.getMessage, pos)
85
+ EmptyTree
86
+ case NonFatal (ex) =>
87
+ val msg =
88
+ s """ Failed to evaluate inlined quote.
89
+ | Caused by ${ex.getClass}: ${if (ex.getMessage == null ) " " else ex.getMessage}
90
+ | ${ex.getStackTrace.takeWhile(_.getClassName != " dotty.tools.dotc.transform.Splicer$" ).init.mkString(" \n " )}
91
+ """ .stripMargin
92
+ ctx.error(msg, pos)
93
+ EmptyTree
94
+ }
95
+ }
96
+
90
97
/** Tree interpreter that can interpret calls to static methods with it's default arguments
91
98
*
92
99
* The interpreter assumes that all calls in the trees are to code that was
0 commit comments