File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
compiler/src/dotty/tools/dotc/core/quoted Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import scala.reflect.ClassTag
22
22
object PickledQuotes {
23
23
import tpd ._
24
24
25
- /** Pickle the tree of the a quoted.Expr */
25
+ /** Pickle the tree of the quoted.Expr */
26
26
def pickleExpr (tree : Tree )(implicit ctx : Context ): scala.quoted.Expr [Any ] = {
27
27
// Check that there are no free variables
28
28
new TreeTraverser {
Original file line number Diff line number Diff line change @@ -5,7 +5,14 @@ import scala.runtime.quoted.Unpickler.Pickled
5
5
6
6
sealed abstract class Expr [T ] {
7
7
final def unary_~ : T = throw new Error (" ~ should have been compiled away" )
8
+
9
+ /** Evaluate the contents of this expression and return the result.
10
+ *
11
+ * May throw a FreeVariableError on expressions that came from an inline macro.
12
+ */
8
13
final def run (implicit toolbox : Toolbox [T ]): T = toolbox.run(this )
14
+
15
+ /** Show a source code like representation of this expression */
9
16
final def show (implicit toolbox : Toolbox [T ]): String = toolbox.show(this )
10
17
}
11
18
@@ -36,7 +43,13 @@ object Exprs {
36
43
override def toString : String = s " Expr( $value) "
37
44
}
38
45
39
- /** An Expr backed by a tree. Only the current compiler trees are allowed. */
46
+ /** An Expr backed by a tree. Only the current compiler trees are allowed.
47
+ *
48
+ * These expressions are used for arguments of inline macros. They contain and actual tree
49
+ * from the program that is being expanded by the macro.
50
+ *
51
+ * May contain references to code defined outside this Expr instance.
52
+ */
40
53
final class TreeExpr [Tree ](val tree : Tree , pickle : => Expr [_]) extends quoted.Expr [Any ] {
41
54
def pickled [T ]: Expr [T ] = pickle.asInstanceOf [Expr [T ]]
42
55
override def toString : String = s " Expr(<raw>) "
Original file line number Diff line number Diff line change 1
1
package scala .quoted
2
2
3
+ /** Exception is thrown when trying to evaluate the contents of an expression
4
+ * that has free variables (i.e. has some local references to code that is
5
+ * outside of the expression). This can happen on Expr that passed as arguments to
6
+ * an inline macro.
7
+ */
3
8
class FreeVariableError (val name : String ) extends QuoteError (" Free variable " + name + " could not be handled" )
You can’t perform that action at this time.
0 commit comments