summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2011-12-25 11:06:04 +0100
committerEugene Burmako <xeno.by@gmail.com>2011-12-26 22:48:33 +0100
commit8f2d318ee2e09baee4e42da73aafb6999ff3874c (patch)
tree1cb705ccbf52472fccc5381de0087b85f65e915c
parentf737e35ddf43599043ab78404c4f9a13e6d02c9b (diff)
downloadscala-8f2d318ee2e09baee4e42da73aafb6999ff3874c.tar.gz
scala-8f2d318ee2e09baee4e42da73aafb6999ff3874c.tar.bz2
scala-8f2d318ee2e09baee4e42da73aafb6999ff3874c.zip
A handful of tests for closures under reification
-rw-r--r--test/pending/run/reify_closure1.check2
-rw-r--r--test/pending/run/reify_closure1.scala20
-rw-r--r--test/pending/run/reify_closure2a.check2
-rw-r--r--test/pending/run/reify_closure2a.scala20
-rw-r--r--test/pending/run/reify_closure2b.check2
-rw-r--r--test/pending/run/reify_closure2b.scala22
-rw-r--r--test/pending/run/reify_closure3a.check2
-rw-r--r--test/pending/run/reify_closure3a.scala22
-rw-r--r--test/pending/run/reify_closure3b.check2
-rw-r--r--test/pending/run/reify_closure3b.scala24
-rw-r--r--test/pending/run/reify_closure4a.check2
-rw-r--r--test/pending/run/reify_closure4a.scala22
-rw-r--r--test/pending/run/reify_closure4b.check2
-rw-r--r--test/pending/run/reify_closure4b.scala24
-rw-r--r--test/pending/run/reify_closure5a.check2
-rw-r--r--test/pending/run/reify_closure5a.scala20
-rw-r--r--test/pending/run/reify_closure5b.check2
-rw-r--r--test/pending/run/reify_closure5b.scala22
-rw-r--r--test/pending/run/reify_closure6.check3
-rw-r--r--test/pending/run/reify_closure6.scala26
20 files changed, 243 insertions, 0 deletions
diff --git a/test/pending/run/reify_closure1.check b/test/pending/run/reify_closure1.check
new file mode 100644
index 0000000000..b2f7f08c17
--- /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 0000000000..825a38dc1d
--- /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 0000000000..c1f3abd7e6
--- /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 0000000000..b88bec005d
--- /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 0000000000..c1f3abd7e6
--- /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 0000000000..e9fb40bede
--- /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 0000000000..c1f3abd7e6
--- /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 0000000000..6414fa58a3
--- /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 0000000000..c1f3abd7e6
--- /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 0000000000..5c4f3c81b9
--- /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 0000000000..c1f3abd7e6
--- /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 0000000000..99e9d82706
--- /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 0000000000..c1f3abd7e6
--- /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 0000000000..24dfa9fe17
--- /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 0000000000..df9e19c591
--- /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 0000000000..0ac53d5479
--- /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 0000000000..df9e19c591
--- /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 0000000000..02eb771f0c
--- /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 0000000000..3526d04b0e
--- /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 0000000000..909071aa44
--- /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)
+}