Skip to content

Commit 68e32ab

Browse files
committed
Add documentation
1 parent 3b0128a commit 68e32ab

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.reflect.ClassTag
2222
object PickledQuotes {
2323
import tpd._
2424

25-
/** Pickle the tree of the a quoted.Expr */
25+
/** Pickle the tree of the quoted.Expr */
2626
def pickleExpr(tree: Tree)(implicit ctx: Context): scala.quoted.Expr[Any] = {
2727
// Check that there are no free variables
2828
new TreeTraverser {

library/src/scala/quoted/Expr.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import scala.runtime.quoted.Unpickler.Pickled
55

66
sealed abstract class Expr[T] {
77
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+
*/
813
final def run(implicit toolbox: Toolbox[T]): T = toolbox.run(this)
14+
15+
/** Show a source code like representation of this expression */
916
final def show(implicit toolbox: Toolbox[T]): String = toolbox.show(this)
1017
}
1118

@@ -36,7 +43,13 @@ object Exprs {
3643
override def toString: String = s"Expr($value)"
3744
}
3845

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+
*/
4053
final class TreeExpr[Tree](val tree: Tree, pickle: => Expr[_]) extends quoted.Expr[Any] {
4154
def pickled[T]: Expr[T] = pickle.asInstanceOf[Expr[T]]
4255
override def toString: String = s"Expr(<raw>)"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
package scala.quoted
22

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+
*/
38
class FreeVariableError(val name: String) extends QuoteError("Free variable " + name + " could not be handled")

0 commit comments

Comments
 (0)