@@ -36,7 +36,22 @@ 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
+ try {
40
+ val evaluated = interpreted.map(lambda => lambda(liftedArgs).asInstanceOf [scala.quoted.Expr [Nothing ]])
41
+ 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
+ }
40
55
}
41
56
42
57
/** Given the inline code and bindings, compute the lifted arguments that will be used to execute the macro
@@ -72,23 +87,6 @@ object Splicer {
72
87
liftArgs(call.symbol.info, allArgs(call, Nil ))
73
88
}
74
89
75
- private def evaluateLambda (lambda : Seq [Any ] => Object , args : Seq [Any ], pos : Position )(implicit ctx : Context ): Option [scala.quoted.Expr [Nothing ]] = {
76
- try Some (lambda(args).asInstanceOf [scala.quoted.Expr [Nothing ]])
77
- catch {
78
- case ex : scala.quoted.QuoteError =>
79
- ctx.error(ex.getMessage, pos)
80
- None
81
- case NonFatal (ex) =>
82
- val msg =
83
- s """ Failed to evaluate inlined quote.
84
- | Caused by: ${ex.getMessage}
85
- | ${ex.getStackTrace.takeWhile(_.getClassName != " dotty.tools.dotc.transform.Splicer$" ).init.mkString(" \n " )}
86
- """ .stripMargin
87
- ctx.error(msg, pos)
88
- None
89
- }
90
- }
91
-
92
90
/** Tree interpreter that can interpret calls to static methods with it's default arguments
93
91
*
94
92
* The interpreter assumes that all calls in the trees are to code that was
0 commit comments