summaryrefslogtreecommitdiff
path: root/test/files/run/t5274_2.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-02-02 15:29:55 +0100
committerEugene Burmako <xeno.by@gmail.com>2012-02-02 15:29:55 +0100
commit363f8af6a8c157485a644d00d75e2df10e71e661 (patch)
tree2cd691f5966c0c823f85abc94f8eef0057f676ff /test/files/run/t5274_2.scala
parentd940371bd50098c4146e52941880ccdbcb4ea47a (diff)
downloadscala-363f8af6a8c157485a644d00d75e2df10e71e661.tar.gz
scala-363f8af6a8c157485a644d00d75e2df10e71e661.tar.bz2
scala-363f8af6a8c157485a644d00d75e2df10e71e661.zip
Fixes reifyThis
Diffstat (limited to 'test/files/run/t5274_2.scala')
-rw-r--r--test/files/run/t5274_2.scala57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/files/run/t5274_2.scala b/test/files/run/t5274_2.scala
new file mode 100644
index 0000000000..42991fe5d2
--- /dev/null
+++ b/test/files/run/t5274_2.scala
@@ -0,0 +1,57 @@
+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{
+ /** Nested methods can use and even update everything
+ * visible in their scope (including local variables or
+ * arguments of enclosing methods).
+ */
+ def sort(a: Array[Int]) {
+
+ def swap(i: Int, j: Int) {
+ val t = a(i); a(i) = a(j); a(j) = t
+ }
+
+ def sort1(l: Int, r: Int) {
+ val pivot = a((l + r) / 2)
+ var i = l
+ var j = r
+ while (i <= j) {
+ while (a(i) < pivot) i += 1
+ while (a(j) > pivot) j -= 1
+ if (i <= j) {
+ swap(i, j)
+ i += 1
+ j -= 1
+ }
+ }
+ if (l < j) sort1(l, j)
+ if (j < r) sort1(i, r)
+ }
+
+ if (a.length > 0)
+ sort1(0, a.length - 1)
+ }
+
+ def println(ar: Array[Int]) {
+ def print1 = {
+ def iter(i: Int): String =
+ ar(i) + (if (i < ar.length-1) "," + iter(i+1) else "")
+ if (ar.length == 0) "" else iter(0)
+ }
+ Console.println("[" + print1 + "]")
+ }
+
+ val ar = Array(6, 2, 8, 5, 1)
+ println(ar)
+ sort(ar)
+ println(ar)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}