@@ -7,6 +7,8 @@ import dotty.tools.dotc.core.Decorators._
77import dotty .tools .dotc .core .quoted ._
88import dotty .tools .dotc .interpreter ._
99
10+ import scala .util .control .NonFatal
11+
1012import java .lang .reflect .InvocationTargetException
1113
1214/** Utility class to splice quoted expressions */
@@ -25,17 +27,21 @@ object Splicer {
2527 /** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */
2628 private def reflectiveSplice (tree : Tree )(implicit ctx : Context ): Tree = {
2729 val interpreter = new Interpreter
28- try {
29- interpreter.interpretTree[scala.quoted.Expr [_]](tree).map(PickledQuotes .quotedExprToTree).getOrElse(tree)
30- } catch {
31- case ex : InvocationTargetException => tryRecoverFromTargetException(tree, ex)
32- }
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)
3334 }
3435
35- private def tryRecoverFromTargetException (tree : Tree , ex : InvocationTargetException )(implicit ctx : Context ): Tree = ex.getCause match {
36- case ex : scala.quoted.QuoteError =>
37- ctx.error(ex.getMessage, tree.pos)
38- EmptyTree
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)
3945 case _ => throw ex
4046 }
4147
0 commit comments