@@ -36,24 +36,31 @@ 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
46
+ /* Evaluate the code in the macro and handle exceptions durring evaluation */
47
+ private def evaluateMacro (pos : Position )(code : => Tree )(implicit ctx : Context ): Tree = {
48
+ try code
49
+ catch {
50
+ case ex : scala.quoted.QuoteError =>
51
+ ctx.error(ex.getMessage, pos)
52
+ EmptyTree
53
+ case NonFatal (ex) =>
54
+ val msg =
55
+ s """ Failed to evaluate inlined quote.
56
+ | Caused by ${ex.getClass}: ${if (ex.getMessage == null ) " " else ex.getMessage}
57
+ | ${ex.getStackTrace.takeWhile(_.getClassName != " dotty.tools.dotc.transform.Splicer$" ).init.mkString(" \n " )}
58
+ """ .stripMargin
59
+ ctx.error(msg, pos)
60
+ EmptyTree
61
+ }
62
+ }
63
+
57
64
/** Given the inline code and bindings, compute the lifted arguments that will be used to execute the macro
58
65
* - Type parameters are lifted to quoted.Types.TreeType
59
66
* - Inline parameters are listed as their value
0 commit comments