A dummy method to mark expression splicing in reification.
It should only be used within a reify
call, which eliminates the splice
call and embeds the wrapped tree into the reified surrounding expression. If used alone splice
throws an exception when called at runtime.
If you want to use an Expr in reification of some Scala code, you need to splice it in. For an expr of type Expr[T]
, where T
has a method foo
, the following code
reify{ expr.splice.foo }
uses splice to turn an expr of type Expr[T] into a value of type T in the context of reify
.
It is equivalent to
Select( expr.tree, TermName("foo") )
The following example code however does not compile
reify{ expr.foo }
because expr of type Expr[T] itself does not have a method foo.
Type of the wrapped expression tree as provided during creation.
When exprs are created by the compiler, staticType
represents a statically known type of the tree as calculated at that point by the compiler.
A dummy value to denote cross-stage path-dependent type dependencies.
For example for the following macro definition:
class X { type T } object Macros { def foo(x: X): x.T = macro Impls.foo_impl }
The corresponding macro implementation should have the following signature (note how the return type denotes path-dependency on x):
object Impls { def foo_impl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ... }
© 2002-2019 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://www.scala-lang.org/api/2.13.0/scala-reflect/scala/reflect/api/Exprs$Expr.html
Expr wraps an abstract syntax tree and tags it with its type. The main source of information about exprs is the scala.reflect.api.Exprs page.