scala -Xprint:typer -e "class A(val i: Int)"
prints the desugarred expression after the typer
phase. Use scala -Xshow-phases
to get a list of all phases.
Paste this into a REPL session or in a file loaded with the :load
command:
import scala.reflect.macros.Context
import scala.reflect.runtime.universe._
import scala.language.experimental.macros
def desugarImpl(c : Context)(expr : c.Expr[Any]): c.Expr[Unit] = {
import c.universe._
println(show(expr.tree))
reify {}
}
def desugar(expr : Any) = macro desugarImpl
Use this little piece of awesomnes:
scala> desugar{
| class A(i: Int)
| }
{
class A extends scala.AnyRef {
<paramaccessor> private[this] val i: Int = _;
def <init>(i: Int): A = {
A.super.<init>();
()
}
};
()
}
Credits go to http://stackoverflow.com/questions/9891407/getting-the-desugared-part-of-a-scala-for-comprehension-expression