summaryrefslogtreecommitdiff
path: root/test/pending/run/reify_complex.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2011-12-05 17:00:55 +0100
committerEugene Burmako <xeno.by@gmail.com>2011-12-05 17:00:55 +0100
commit6e9ae187a05b1ca4fe748d8a7b45440a55ceb589 (patch)
treeecf9aadb4d8e122ebc4be30997bc3b52880b2521 /test/pending/run/reify_complex.scala
parenta289465c70630719cbd3a74edf5502a156ef83c4 (diff)
downloadscala-6e9ae187a05b1ca4fe748d8a7b45440a55ceb589.tar.gz
scala-6e9ae187a05b1ca4fe748d8a7b45440a55ceb589.tar.bz2
scala-6e9ae187a05b1ca4fe748d8a7b45440a55ceb589.zip
Another test pack for reflection
Also see https://github.com/scala/scala/pull/25.
Diffstat (limited to 'test/pending/run/reify_complex.scala')
-rw-r--r--test/pending/run/reify_complex.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/pending/run/reify_complex.scala b/test/pending/run/reify_complex.scala
new file mode 100644
index 0000000000..aae4d558cf
--- /dev/null
+++ b/test/pending/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)
+}