aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-03-25 10:46:07 +0100
committerMartin Odersky <odersky@gmail.com>2016-03-30 09:51:03 +0200
commit6d2a3d341128eddb99c0f52bca154f9e8b87eb55 (patch)
treedee1c0b86b4d9fe16ac6c0a2da141b16d1e0ab65 /tests/pos
parent506c10613a4f5223472f76226c37cad1701e9610 (diff)
downloaddotty-6d2a3d341128eddb99c0f52bca154f9e8b87eb55.tar.gz
dotty-6d2a3d341128eddb99c0f52bca154f9e8b87eb55.tar.bz2
dotty-6d2a3d341128eddb99c0f52bca154f9e8b87eb55.zip
Test cases
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/flowops1.scala6
-rw-r--r--tests/pos/named-params.scala48
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/pos/flowops1.scala b/tests/pos/flowops1.scala
index 7cf8eb6ef..649a9b18c 100644
--- a/tests/pos/flowops1.scala
+++ b/tests/pos/flowops1.scala
@@ -20,6 +20,10 @@ object Test {
def xx(i: Int): f.Repr[Out = O] = f.map(identity)
}
+ class xalt[O, M, F <: FO](val f: F[Out = O, Mat = M]) extends AnyVal {
+ def xx(i: Int): FO[Out = O, Mat = M] = ???
+ }
+
val s1 = new Source[Int, NotUsed].xx(12)
val s2: Source[Int, NotUsed] = s1
val f1 = x[Int, NotUsed, Flow[In = Int]](new Flow[Int, Int, NotUsed]).xx(12)
@@ -30,4 +34,6 @@ object Test {
val f4: Flow[Int, Int, NotUsed] = f3
val f5 = new Flow[Int, Int, NotUsed].xx(12)
val f6: Flow[Int, Int, NotUsed] = f5
+ val f7 = new xalt(new Flow[Int, Int, NotUsed]).xx(12)
+ val f8: FO[Int, NotUsed] = f7
}
diff --git a/tests/pos/named-params.scala b/tests/pos/named-params.scala
index bcd64ea4b..3fab24cd2 100644
--- a/tests/pos/named-params.scala
+++ b/tests/pos/named-params.scala
@@ -29,9 +29,39 @@ object Test {
val z3 = d2[E = Int](1)
val z4 = d2[V = Int]("AAA")
val z5 = d2[E = Int][V = String](1)
+
+// Testing type inference
+
+ def f[X <: C](x: X[Int, Int]): X[String, String] = ???
+ val arg1: C[Int, Int] = ???
+ val res1 = f(arg1)
+ val chk1: C[String, String] = res1
+
+ class C1[type Elem, type Value](x: Elem) extends C[Elem, Value](x)
+ class CC extends C1[Int, Int](1)
+ val arg2: CC = ???
+ val res2 = f(arg2)
+ val chk2: C[String, String] = res2
+
+ class D1[type Elem, type Value](x: Elem) extends C[Elem, Value](x)
+ class DD extends D1[Int, Int](2)
+ val arg3: CC & DD = ???
+ val res3 = f(arg3)
+ val chk3: (C1 & D1) { type Elem = String; type Value = String } = res3
+ val arg4: CC | DD = ???
+ val res4 = f(arg4)
+ val chk4: C[String, String] = ???
+
+ class CX[type Elem](x: Elem) extends C1[Elem, Int](x)
+ class DX[type Value]() extends D1[Int, Value](2)
+ val arg5: CX[Int] & DX[Int] = ???
+ val res5 = f(arg5)
+ val chk5: (C1 & D1) { type Elem = String; type Value = String } = res5
+ val chk6: C1[String, String] & D1[String, String] = chk5
+ val chk7: (C1 & D1) { type Elem = String; type Value = String } = chk6
}
-// Adapated from i94-nada
+// Adapted from i94-nada, somewhat non-sensical
trait Test1 {
trait Monad[type Elem] {
def unit: Elem
@@ -40,7 +70,21 @@ trait Test1 {
case class Left[A,B](unit: A) extends Either[A,B] with Monad[A]
case class Right[A,B](unit: B) extends Either[A,B] with Monad[B]
def flatMap[X,Y,M <: Monad](m: M[Elem = X], f: X => M[Elem = Y]): M[Elem = Y] = f(m.unit)
- println(flatMap(Left(1), {x: Int => Left(x)}))
+ val res = flatMap(Left(1), {x: Int => Left(x)})
+ val chk: Either[Int, Nothing] & Monad & Product1[Int] = res
+}
+
+// Adapted from i94-nada, this time with more sense
+trait Test2 {
+ trait Monad[type Elem] {
+ def unit: Elem
+ }
+ sealed abstract class Either[A,B]
+ case class Left[type Elem, B](unit: Elem) extends Either[Elem,B] with Monad[Elem]
+ case class Right[A, type Elem](unit: Elem) extends Either[A,Elem] with Monad[Elem]
+ def flatMap[X,Y,M <: Monad](m: M[Elem = X], f: X => M[Elem = Y]): M[Elem = Y] = f(m.unit)
+ val res = flatMap(Left(1), {x: Int => Left(x)})
+ val chk: Left[Int, Nothing] = res
}