summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-02-02 14:39:44 +0100
committerEugene Burmako <xeno.by@gmail.com>2012-02-02 14:39:44 +0100
commitd940371bd50098c4146e52941880ccdbcb4ea47a (patch)
tree2d4f7093fad48fcaf44ac491bf3a13e3cc2bcbe0 /test/files
parent3aebe255b87f534239f0c46a2a6e0d696c8a31d4 (diff)
downloadscala-d940371bd50098c4146e52941880ccdbcb4ea47a.tar.gz
scala-d940371bd50098c4146e52941880ccdbcb4ea47a.tar.bz2
scala-d940371bd50098c4146e52941880ccdbcb4ea47a.zip
Miscellaneous fixes to reification
More specifically: * Importers now preserve wasEmpty and original * ToolBoxes no longer auto-evaluate nullary functions returned by runExpr * All local symbols from previous typechecks are now correctly erased by ResetAttrs * Originals are now reified
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/code.check7
-rw-r--r--test/files/run/reify_complex.check1
-rw-r--r--test/files/run/reify_complex.scala31
-rw-r--r--test/files/run/reify_extendbuiltins.check1
-rw-r--r--test/files/run/reify_extendbuiltins.scala21
-rw-r--r--test/files/run/reify_generic2.check1
-rw-r--r--test/files/run/reify_generic2.scala16
-rw-r--r--test/files/run/reify_getter.check1
-rw-r--r--test/files/run/reify_getter.scala19
-rw-r--r--test/files/run/reify_sort1.check2
-rw-r--r--test/files/run/reify_sort1.scala27
-rw-r--r--test/files/run/t5269.check1
-rw-r--r--test/files/run/t5269.scala22
-rw-r--r--test/files/run/t5274_1.check3
-rw-r--r--test/files/run/t5274_1.scala20
-rw-r--r--test/files/run/t5275.check1
-rw-r--r--test/files/run/t5275.scala15
-rw-r--r--test/files/run/t5277_1.check1
-rw-r--r--test/files/run/t5277_1.scala21
-rw-r--r--test/files/run/t5277_2.check2
-rw-r--r--test/files/run/t5277_2.scala18
-rw-r--r--test/files/run/t5335.check1
-rw-r--r--test/files/run/t5335.scala14
23 files changed, 246 insertions, 0 deletions
diff --git a/test/files/run/code.check b/test/files/run/code.check
index b946554fda..9b0351bbf9 100644
--- a/test/files/run/code.check
+++ b/test/files/run/code.check
@@ -1,29 +1,36 @@
testing: ((x: Int) => x.$plus(ys.length))
+type is: Int => Int
result = ((x: Int) => x.+{(x: <?>)Int}(ys.length{Int}){Int}){Int => Int}
evaluated = <function1>
testing: (() => {
val e: Element = new Element("someName");
e
})
+type is: () => Element
result = (() => {
val e: Element = new Element{Element}{(name: <?>)Element}("someName"{String("someName")}){Element};
e{Element}
}{Element}){() => Element}
evaluated = Element(someName)
testing: (() => truc.elem = 6)
+type is: () => Unit
result = (() => truc.elem{Int} = 6{Int(6)}{Unit}){() => Unit}
evaluated = null
testing: (() => truc.elem = truc.elem.$plus(6))
+type is: () => Unit
result = (() => truc.elem{Int} = truc.elem.+{(x: <?>)Int}(6{Int(6)}){Int}{Unit}){() => Unit}
evaluated = null
testing: (() => new baz.BazElement("someName"))
+type is: () => baz.BazElement
result = (() => new baz.BazElement{baz.BazElement}{(name: <?>)baz.BazElement}("someName"{String("someName")}){baz.BazElement}){() => baz.BazElement}
evaluated = BazElement(someName)
testing: ((x: Int) => x.$plus(ys.length))
+type is: Int => Int
result = ((x: Int) => x.+{(x: <?>)Int}(ys.length{Int}){Int}){Int => Int}
evaluated = <function1>
static: 2
testing: (() => x.$plus(1))
+type is: () => Int
result = (() => x.+{(x: <?>)Int}(1{Int(1)}){Int}){() => Int}
evaluated = 2
1+1 = 2
diff --git a/test/files/run/reify_complex.check b/test/files/run/reify_complex.check
new file mode 100644
index 0000000000..7df35e33a0
--- /dev/null
+++ b/test/files/run/reify_complex.check
@@ -0,0 +1 @@
+3.0+4.0*i
diff --git a/test/files/run/reify_complex.scala b/test/files/run/reify_complex.scala
new file mode 100644
index 0000000000..aae4d558cf
--- /dev/null
+++ b/test/files/run/reify_complex.scala
@@ -0,0 +1,31 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ class Complex(val re: Double, val im: Double) {
+ def + (that: Complex) =
+ new Complex(re + that.re, im + that.im)
+ def - (that: Complex) =
+ new Complex(re - that.re, im - that.im)
+ def * (that: Complex) =
+ new Complex(re * that.re - im * that.im,
+ re * that.im + im * that.re)
+ def / (that: Complex) = {
+ val denom = that.re * that.re + that.im * that.im
+ new Complex((re * that.re + im * that.im) / denom,
+ (im * that.re - re * that.im) / denom)
+ }
+ override def toString =
+ re + (if (im < 0) "-" + (-im) else "+" + im) + "*i"
+ }
+ val x = new Complex(2, 1); val y = new Complex(1, 3)
+ println(x + y)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/reify_extendbuiltins.check b/test/files/run/reify_extendbuiltins.check
new file mode 100644
index 0000000000..a48033a30d
--- /dev/null
+++ b/test/files/run/reify_extendbuiltins.check
@@ -0,0 +1 @@
+10! = 3628800
diff --git a/test/files/run/reify_extendbuiltins.scala b/test/files/run/reify_extendbuiltins.scala
new file mode 100644
index 0000000000..57acd699ff
--- /dev/null
+++ b/test/files/run/reify_extendbuiltins.scala
@@ -0,0 +1,21 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def fact(n: Int): BigInt =
+ if (n == 0) 1 else fact(n-1) * n
+ class Factorizer(n: Int) {
+ def ! = fact(n)
+ }
+ implicit def int2fact(n: Int) = new Factorizer(n)
+
+ println("10! = " + (10!))
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/reify_generic2.check b/test/files/run/reify_generic2.check
new file mode 100644
index 0000000000..b8626c4cff
--- /dev/null
+++ b/test/files/run/reify_generic2.check
@@ -0,0 +1 @@
+4
diff --git a/test/files/run/reify_generic2.scala b/test/files/run/reify_generic2.scala
new file mode 100644
index 0000000000..d03fe7602b
--- /dev/null
+++ b/test/files/run/reify_generic2.scala
@@ -0,0 +1,16 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ class C
+ val product = List(new C, new C).length * List[C](new C, new C).length
+ println(product)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/reify_getter.check b/test/files/run/reify_getter.check
new file mode 100644
index 0000000000..5ef4ff4d04
--- /dev/null
+++ b/test/files/run/reify_getter.check
@@ -0,0 +1 @@
+evaluated = 2
diff --git a/test/files/run/reify_getter.scala b/test/files/run/reify_getter.scala
new file mode 100644
index 0000000000..83eaded506
--- /dev/null
+++ b/test/files/run/reify_getter.scala
@@ -0,0 +1,19 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ class C {
+ val x = 2
+ }
+
+ new C().x
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ val evaluated = toolbox.runExpr(ttree)
+ println("evaluated = " + evaluated)
+}
diff --git a/test/files/run/reify_sort1.check b/test/files/run/reify_sort1.check
new file mode 100644
index 0000000000..0d30805141
--- /dev/null
+++ b/test/files/run/reify_sort1.check
@@ -0,0 +1,2 @@
+List(6, 2, 8, 5, 1)
+List(1, 2, 5, 6, 8)
diff --git a/test/files/run/reify_sort1.scala b/test/files/run/reify_sort1.scala
new file mode 100644
index 0000000000..42f4c824a5
--- /dev/null
+++ b/test/files/run/reify_sort1.scala
@@ -0,0 +1,27 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def sort(a: List[Int]): List[Int] = {
+ if (a.length < 2)
+ a
+ else {
+ val pivot = a(a.length / 2)
+ sort(a.filter(_ < pivot)) :::
+ a.filter(_ == pivot) :::
+ sort(a.filter(_ > pivot))
+ }
+ }
+
+ val xs = List(6, 2, 8, 5, 1)
+ println(xs)
+ println(sort(xs))
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/t5269.check b/test/files/run/t5269.check
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/test/files/run/t5269.check
@@ -0,0 +1 @@
+2
diff --git a/test/files/run/t5269.scala b/test/files/run/t5269.scala
new file mode 100644
index 0000000000..a30509f3fe
--- /dev/null
+++ b/test/files/run/t5269.scala
@@ -0,0 +1,22 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ trait Z {
+ val z = 2
+ }
+
+ class X extends Z {
+ def println() = Predef.println(z)
+ }
+
+ new X().println()
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/t5274_1.check b/test/files/run/t5274_1.check
new file mode 100644
index 0000000000..fca8bc3d3e
--- /dev/null
+++ b/test/files/run/t5274_1.check
@@ -0,0 +1,3 @@
+50! = 30414093201713378043612608166064768844377641568960512000000000000
+49! = 608281864034267560872252163321295376887552831379210240000000000
+50!/49! = 50
diff --git a/test/files/run/t5274_1.scala b/test/files/run/t5274_1.scala
new file mode 100644
index 0000000000..c501172518
--- /dev/null
+++ b/test/files/run/t5274_1.scala
@@ -0,0 +1,20 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def factorial(n: BigInt): BigInt =
+ if (n == 0) 1 else n * factorial(n-1)
+
+ val f50 = factorial(50); val f49 = factorial(49)
+ println("50! = " + f50)
+ println("49! = " + f49)
+ println("50!/49! = " + (f50 / f49))
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/t5275.check b/test/files/run/t5275.check
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/test/files/run/t5275.check
@@ -0,0 +1 @@
+2
diff --git a/test/files/run/t5275.scala b/test/files/run/t5275.scala
new file mode 100644
index 0000000000..d419834ded
--- /dev/null
+++ b/test/files/run/t5275.scala
@@ -0,0 +1,15 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ class C(val foo: Int)
+ println(new C(2).foo)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/t5277_1.check b/test/files/run/t5277_1.check
new file mode 100644
index 0000000000..a48033a30d
--- /dev/null
+++ b/test/files/run/t5277_1.check
@@ -0,0 +1 @@
+10! = 3628800
diff --git a/test/files/run/t5277_1.scala b/test/files/run/t5277_1.scala
new file mode 100644
index 0000000000..57acd699ff
--- /dev/null
+++ b/test/files/run/t5277_1.scala
@@ -0,0 +1,21 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def fact(n: Int): BigInt =
+ if (n == 0) 1 else fact(n-1) * n
+ class Factorizer(n: Int) {
+ def ! = fact(n)
+ }
+ implicit def int2fact(n: Int) = new Factorizer(n)
+
+ println("10! = " + (10!))
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/t5277_2.check b/test/files/run/t5277_2.check
new file mode 100644
index 0000000000..ca017e2a40
--- /dev/null
+++ b/test/files/run/t5277_2.check
@@ -0,0 +1,2 @@
+2()
+1()
diff --git a/test/files/run/t5277_2.scala b/test/files/run/t5277_2.scala
new file mode 100644
index 0000000000..67b6b000bc
--- /dev/null
+++ b/test/files/run/t5277_2.scala
@@ -0,0 +1,18 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def p(implicit i: Int) = print(i)
+ implicit val v = 2
+
+ println(p)
+ println(p(1))
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/t5335.check b/test/files/run/t5335.check
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/test/files/run/t5335.check
@@ -0,0 +1 @@
+2
diff --git a/test/files/run/t5335.scala b/test/files/run/t5335.scala
new file mode 100644
index 0000000000..9a8b91f04d
--- /dev/null
+++ b/test/files/run/t5335.scala
@@ -0,0 +1,14 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ println(new {def x = 2}.x)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}