@@ -36,7 +36,11 @@ 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
- interpreted.flatMap(lambda => evaluateLambda(lambda, liftedArgs, pos)).fold(tree)(PickledQuotes .quotedExprToTree)
39
+ evaluateMacro(pos) {
40
+ // Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree
41
+ val evaluated = interpreted.map(lambda => lambda(liftedArgs).asInstanceOf [scala.quoted.Expr [Nothing ]])
42
+ evaluated.fold(tree)(PickledQuotes .quotedExprToTree)
43
+ }
40
44
}
41
45
42
46
/** Given the inline code and bindings, compute the lifted arguments that will be used to execute the macro
@@ -73,20 +77,21 @@ object Splicer {
73
77
liftArgs(call.symbol.info, allArgs(call, Nil ))
74
78
}
75
79
76
- private def evaluateLambda (lambda : Seq [Any ] => Object , args : Seq [Any ], pos : Position )(implicit ctx : Context ): Option [scala.quoted.Expr [Nothing ]] = {
77
- try Some (lambda(args).asInstanceOf [scala.quoted.Expr [Nothing ]])
80
+ /* Evaluate the code in the macro and handle exceptions durring evaluation */
81
+ private def evaluateMacro (pos : Position )(code : => Tree )(implicit ctx : Context ): Tree = {
82
+ try code
78
83
catch {
79
84
case ex : scala.quoted.QuoteError =>
80
85
ctx.error(ex.getMessage, pos)
81
- None
86
+ EmptyTree
82
87
case NonFatal (ex) =>
83
88
val msg =
84
89
s """ Failed to evaluate inlined quote.
85
- | Caused by: ${ex.getMessage}
86
- | ${ex.getStackTrace.takeWhile(_.getClassName != " dotty.tools.dotc.transform.Splicer$" ).init.mkString(" \n " )}
90
+ | Caused by ${ex.getClass} : ${if (ex.getMessage == null ) " " else ex.getMessage}
91
+ | ${ex.getStackTrace.takeWhile(_.getClassName != " dotty.tools.dotc.transform.Splicer$" ).init.mkString(" \n " )}
87
92
""" .stripMargin
88
93
ctx.error(msg, pos)
89
- None
94
+ EmptyTree
90
95
}
91
96
}
92
97
0 commit comments