summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-10-29 19:34:10 +0000
committerPaul Phillips <paulp@improving.org>2011-10-29 19:34:10 +0000
commitbcf53cbe913a99bb243b5782da644cf0efecc598 (patch)
tree0f19aff170e8b62bd6608cac3e921033a6a77813
parent1b68611e04da4a4fb4ac48a96718e088f0ed432c (diff)
downloadscala-bcf53cbe913a99bb243b5782da644cf0efecc598.tar.gz
scala-bcf53cbe913a99bb243b5782da644cf0efecc598.tar.bz2
scala-bcf53cbe913a99bb243b5782da644cf0efecc598.zip
Test case closes SI-4957.
No review.
-rw-r--r--test/files/pos/t4957.scala89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/files/pos/t4957.scala b/test/files/pos/t4957.scala
new file mode 100644
index 0000000000..7f037ee25d
--- /dev/null
+++ b/test/files/pos/t4957.scala
@@ -0,0 +1,89 @@
+// a.scala
+// Sat Oct 29 10:06:51 PDT 2011
+
+package simple
+
+import scala.{Double=>double, Int=>int}
+
+/**
+ * @author Christoph Radig
+ */
+
+trait Vector {
+
+ def xd: double
+ def yd: double
+}
+
+object Vector {
+
+ def apply(x: double, y: double) = Double(x, y)
+ def apply(x: int, y: int) = Int(x, y)
+
+ trait Companion[@specialized(double, int) T] {
+
+ type I <: Instance[T]
+
+ def apply(x: T, y: T): I // I (= this.type#I) or this.I?
+
+ lazy val zero: I = apply(numeric.zero, numeric.zero)
+
+ val numeric: Numeric[T]
+ }
+
+ trait Instance[@specialized(double, int) T] extends Vector {
+
+ type C <: Companion[T]
+ def companion: C
+
+ def numeric: Numeric[T] = companion.numeric
+
+ val x: T
+ val y: T
+
+ def xd = numeric.toDouble(x)
+ def yd = numeric.toDouble(y)
+
+ def + (that: C#I): C#I = companion(numeric.plus(this.x, that.x), numeric.plus(this.y, that.y))
+ def - (that: C#I): C#I = companion(numeric.minus(this.x, that.x), numeric.minus(this.y, that.y))
+
+ /**
+ * scalar multiplication
+ */
+ def * (scalar: T): C#I = companion(numeric.times(this.x, scalar), numeric.times(this.y, scalar))
+ }
+
+ object Double extends Companion[double] {
+
+ type I = Double
+
+ def apply(x: double, y: double) = new Double(x, y)
+
+ val numeric = Numeric.DoubleIsFractional
+ }
+
+ final class Double(val x: double, val y: double) extends Instance[double] {
+
+ type C = Double.type
+ def companion = Double
+
+ @inline override def xd = x
+ @inline override def yd = y
+ }
+
+
+ object Int extends Companion[int] {
+
+ type I = Int
+
+ def apply(x: int, y: int) = new Int(x, y)
+
+ val numeric = Numeric.IntIsIntegral
+ }
+
+ final class Int(val x: int, val y: int) extends Instance[int] {
+
+ type C = Int.type
+ def companion = Int
+ }
+}