blob: 8355c51e065af6939c3cc6f917a62348bf25ac66 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import reflect.runtime.Mirror.ToolBox
import scala.tools.nsc.reporters._
import scala.tools.nsc.Settings
object Test extends App {
def foo[T](ys: List[T]) = {
val fun: reflect.Code[Int => Int] = x => x + ys.length
fun
}
val code = foo(List(2))
val tree = code.tree.asInstanceOf[scala.reflect.runtime.Mirror.Tree]
val targetType = code.manifest.tpe.asInstanceOf[scala.reflect.runtime.Mirror.Type]
val reporter = new ConsoleReporter(new Settings)
val toolbox = new ToolBox(reporter, args mkString " ")
val ttree = toolbox.typeCheck(tree, targetType)
println("result = "+ttree)
}
|