From 8f2d318ee2e09baee4e42da73aafb6999ff3874c Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sun, 25 Dec 2011 11:06:04 +0100 Subject: [PATCH] A handful of tests for closures under reification --- test/pending/run/reify_closure1.check | 2 ++ test/pending/run/reify_closure1.scala | 20 ++++++++++++++++++++ test/pending/run/reify_closure2a.check | 2 ++ test/pending/run/reify_closure2a.scala | 20 ++++++++++++++++++++ test/pending/run/reify_closure2b.check | 2 ++ test/pending/run/reify_closure2b.scala | 22 ++++++++++++++++++++++ test/pending/run/reify_closure3a.check | 2 ++ test/pending/run/reify_closure3a.scala | 22 ++++++++++++++++++++++ test/pending/run/reify_closure3b.check | 2 ++ test/pending/run/reify_closure3b.scala | 24 ++++++++++++++++++++++++ test/pending/run/reify_closure4a.check | 2 ++ test/pending/run/reify_closure4a.scala | 22 ++++++++++++++++++++++ test/pending/run/reify_closure4b.check | 2 ++ test/pending/run/reify_closure4b.scala | 24 ++++++++++++++++++++++++ test/pending/run/reify_closure5a.check | 2 ++ test/pending/run/reify_closure5a.scala | 20 ++++++++++++++++++++ test/pending/run/reify_closure5b.check | 2 ++ test/pending/run/reify_closure5b.scala | 22 ++++++++++++++++++++++ test/pending/run/reify_closure6.check | 3 +++ test/pending/run/reify_closure6.scala | 26 ++++++++++++++++++++++++++ 20 files changed, 243 insertions(+) create mode 100644 test/pending/run/reify_closure1.check create mode 100644 test/pending/run/reify_closure1.scala create mode 100644 test/pending/run/reify_closure2a.check create mode 100644 test/pending/run/reify_closure2a.scala create mode 100644 test/pending/run/reify_closure2b.check create mode 100644 test/pending/run/reify_closure2b.scala create mode 100644 test/pending/run/reify_closure3a.check create mode 100644 test/pending/run/reify_closure3a.scala create mode 100644 test/pending/run/reify_closure3b.check create mode 100644 test/pending/run/reify_closure3b.scala create mode 100644 test/pending/run/reify_closure4a.check create mode 100644 test/pending/run/reify_closure4a.scala create mode 100644 test/pending/run/reify_closure4b.check create mode 100644 test/pending/run/reify_closure4b.scala create mode 100644 test/pending/run/reify_closure5a.check create mode 100644 test/pending/run/reify_closure5a.scala create mode 100644 test/pending/run/reify_closure5b.check create mode 100644 test/pending/run/reify_closure5b.scala create mode 100644 test/pending/run/reify_closure6.check create mode 100644 test/pending/run/reify_closure6.scala diff --git a/test/pending/run/reify_closure1.check b/test/pending/run/reify_closure1.check new file mode 100644 index 000000000000..b2f7f08c1707 --- /dev/null +++ b/test/pending/run/reify_closure1.check @@ -0,0 +1,2 @@ +10 +10 diff --git a/test/pending/run/reify_closure1.scala b/test/pending/run/reify_closure1.scala new file mode 100644 index 000000000000..825a38dc1d0e --- /dev/null +++ b/test/pending/run/reify_closure1.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo[T](ys: List[T]): Int => Int = { + val fun: reflect.Code[Int => Int] = x => { + x + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(List(1, 2, 3))(10)) + println(foo(List(1, 2, 3, 4))(10)) +} diff --git a/test/pending/run/reify_closure2a.check b/test/pending/run/reify_closure2a.check new file mode 100644 index 000000000000..c1f3abd7e69f --- /dev/null +++ b/test/pending/run/reify_closure2a.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure2a.scala b/test/pending/run/reify_closure2a.scala new file mode 100644 index 000000000000..b88bec005d2c --- /dev/null +++ b/test/pending/run/reify_closure2a.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + val fun: reflect.Code[Int => Int] = x => { + x + y + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure2b.check b/test/pending/run/reify_closure2b.check new file mode 100644 index 000000000000..c1f3abd7e69f --- /dev/null +++ b/test/pending/run/reify_closure2b.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure2b.scala b/test/pending/run/reify_closure2b.scala new file mode 100644 index 000000000000..e9fb40bede19 --- /dev/null +++ b/test/pending/run/reify_closure2b.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + class Foo(y: Int) { + val fun: reflect.Code[Int => Int] = x => { + x + y + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(y).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure3a.check b/test/pending/run/reify_closure3a.check new file mode 100644 index 000000000000..c1f3abd7e69f --- /dev/null +++ b/test/pending/run/reify_closure3a.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure3a.scala b/test/pending/run/reify_closure3a.scala new file mode 100644 index 000000000000..6414fa58a34f --- /dev/null +++ b/test/pending/run/reify_closure3a.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + def y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure3b.check b/test/pending/run/reify_closure3b.check new file mode 100644 index 000000000000..c1f3abd7e69f --- /dev/null +++ b/test/pending/run/reify_closure3b.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure3b.scala b/test/pending/run/reify_closure3b.scala new file mode 100644 index 000000000000..5c4f3c81b96a --- /dev/null +++ b/test/pending/run/reify_closure3b.scala @@ -0,0 +1,24 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + class Foo(y: Int) { + def y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(y).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure4a.check b/test/pending/run/reify_closure4a.check new file mode 100644 index 000000000000..c1f3abd7e69f --- /dev/null +++ b/test/pending/run/reify_closure4a.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure4a.scala b/test/pending/run/reify_closure4a.scala new file mode 100644 index 000000000000..99e9d8270695 --- /dev/null +++ b/test/pending/run/reify_closure4a.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + val y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure4b.check b/test/pending/run/reify_closure4b.check new file mode 100644 index 000000000000..c1f3abd7e69f --- /dev/null +++ b/test/pending/run/reify_closure4b.check @@ -0,0 +1,2 @@ +11 +12 diff --git a/test/pending/run/reify_closure4b.scala b/test/pending/run/reify_closure4b.scala new file mode 100644 index 000000000000..24dfa9fe1755 --- /dev/null +++ b/test/pending/run/reify_closure4b.scala @@ -0,0 +1,24 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo(y: Int): Int => Int = { + class Foo(y: Int) { + val y1 = y + + val fun: reflect.Code[Int => Int] = x => { + x + y1 + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(y).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(1)(10)) + println(foo(2)(10)) +} diff --git a/test/pending/run/reify_closure5a.check b/test/pending/run/reify_closure5a.check new file mode 100644 index 000000000000..df9e19c591f8 --- /dev/null +++ b/test/pending/run/reify_closure5a.check @@ -0,0 +1,2 @@ +13 +14 diff --git a/test/pending/run/reify_closure5a.scala b/test/pending/run/reify_closure5a.scala new file mode 100644 index 000000000000..0ac53d5479e3 --- /dev/null +++ b/test/pending/run/reify_closure5a.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo[T](ys: List[T]): Int => Int = { + val fun: reflect.Code[Int => Int] = x => { + x + ys.length + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(List(1, 2, 3))(10)) + println(foo(List(1, 2, 3, 4))(10)) +} diff --git a/test/pending/run/reify_closure5b.check b/test/pending/run/reify_closure5b.check new file mode 100644 index 000000000000..df9e19c591f8 --- /dev/null +++ b/test/pending/run/reify_closure5b.check @@ -0,0 +1,2 @@ +13 +14 diff --git a/test/pending/run/reify_closure5b.scala b/test/pending/run/reify_closure5b.scala new file mode 100644 index 000000000000..02eb771f0c56 --- /dev/null +++ b/test/pending/run/reify_closure5b.scala @@ -0,0 +1,22 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + def foo[T](ys: List[T]): Int => Int = { + class Foo[T](ys: List[T]) { + val fun: reflect.Code[Int => Int] = x => { + x + ys.length + } + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(new Foo(ys).fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println(foo(List(1, 2, 3))(10)) + println(foo(List(1, 2, 3, 4))(10)) +} diff --git a/test/pending/run/reify_closure6.check b/test/pending/run/reify_closure6.check new file mode 100644 index 000000000000..3526d04b0ee7 --- /dev/null +++ b/test/pending/run/reify_closure6.check @@ -0,0 +1,3 @@ +first invocation = 15 +second invocation = 18 +q after second invocation = 2 diff --git a/test/pending/run/reify_closure6.scala b/test/pending/run/reify_closure6.scala new file mode 100644 index 000000000000..909071aa445e --- /dev/null +++ b/test/pending/run/reify_closure6.scala @@ -0,0 +1,26 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + var q = 0 + def foo[T](ys: List[T]): Int => Int = { + val z = 1 + var y = 0 + val fun: reflect.Code[Int => Int] = x => { + y += 1 + q += 1 + x + ys.length * z + q + y + } + + val reporter = new ConsoleReporter(new Settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(fun.tree) + val dyn = toolbox.runExpr(ttree) + dyn.asInstanceOf[Int => Int] + } + + println("first invocation = " + foo(List(1, 2, 3))(10)) + println("second invocation = " + foo(List(1, 2, 3, 4))(10)) + println("q after second invocation = " + q) +}