@@ -3,9 +3,14 @@ package transform
3
3
4
4
import dotty .tools .dotc .ast .tpd
5
5
import dotty .tools .dotc .core .Contexts ._
6
+ import dotty .tools .dotc .core .Decorators ._
6
7
import dotty .tools .dotc .core .quoted ._
7
8
import dotty .tools .dotc .interpreter ._
8
9
10
+ import scala .util .control .NonFatal
11
+
12
+ import java .lang .reflect .InvocationTargetException
13
+
9
14
/** Utility class to splice quoted expressions */
10
15
object Splicer {
11
16
import tpd ._
@@ -22,7 +27,22 @@ object Splicer {
22
27
/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */
23
28
private def reflectiveSplice (tree : Tree )(implicit ctx : Context ): Tree = {
24
29
val interpreter = new Interpreter
25
- interpreter.interpretTree[scala.quoted.Expr [_]](tree).map(PickledQuotes .quotedExprToTree).getOrElse(tree)
30
+ val interpreted =
31
+ try interpreter.interpretTree[scala.quoted.Expr [_]](tree)
32
+ catch { case ex : InvocationTargetException => handleTargetException(tree, ex); None }
33
+ interpreted.fold(tree)(PickledQuotes .quotedExprToTree)
34
+ }
35
+
36
+ private def handleTargetException (tree : Tree , ex : InvocationTargetException )(implicit ctx : Context ): Unit = ex.getCause match {
37
+ case ex : scala.quoted.QuoteError => ctx.error(ex.getMessage, tree.pos)
38
+ case NonFatal (ex) =>
39
+ val msg =
40
+ s """ Failed to evaluate inlined quote.
41
+ | Caused by: ${ex.getMessage}
42
+ | ${ex.getStackTrace.takeWhile(_.getClassName != " sun.reflect.NativeMethodAccessorImpl" ).mkString(" \n " )}
43
+ """ .stripMargin
44
+ ctx.error(msg, tree.pos)
45
+ case _ => throw ex
26
46
}
27
47
28
48
}
0 commit comments