summaryrefslogtreecommitdiff
path: root/test/files/run/reify_closure7.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run/reify_closure7.scala')
-rw-r--r--test/files/run/reify_closure7.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/run/reify_closure7.scala b/test/files/run/reify_closure7.scala
new file mode 100644
index 0000000000..46002d8d6c
--- /dev/null
+++ b/test/files/run/reify_closure7.scala
@@ -0,0 +1,31 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ var q = 0
+ var clo: Int => Int = null
+ def foo[T](ys: List[T]): Int => Int = {
+ val z = 1
+ var y = 0
+ val fun = reflect.Code.lift{(x: Int) => {
+ y += 1
+ q += 1
+ println("q = " + q)
+ println("y = " + y)
+ x + ys.length * z + q + y
+ }}
+
+ if (clo == null) {
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val dyn = toolbox.runExpr(fun.tree)
+ clo = dyn.asInstanceOf[Int => Int]
+ }
+
+ clo
+ }
+
+ println("first invocation = " + foo(List(1, 2, 3))(10))
+ println("second invocation = " + foo(List(1, 2, 3, 4))(10))
+}