Does reification of scala expressions work in v2.9?

178 views Asked by At

I was playing around with scala lifting and I accidentally discovered that Scala seems has some sort of implicit support for lambda expressions.

import scala.reflect.Code
import scala.reflect.Function
import scala.reflect.Select

object Test {
  trait Foo {
    def aMethod : String
  }

  val ast : Code[_] = (f:Foo) => f.aMethod 

  //now you can pattern match the AST 
  val Function(_, Select(_, symbol))= ast.tree
  val nameOfAMethod = symbol.name
  println(nameOfAMethod) //prints "aMethod"
}

ast will have the AST for the lambda on the right hand side.

It seems not to work for literals, so:

val ast : Code[_] = 42

does not work.

But this does :

val ast : Code[_] = () => 42

I can't seem to find documentation for it. There doesn't seem to be any implicit conversion active. How does this work?

0

There are 0 answers