aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-03-05 15:56:43 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:14:15 +0100
commit35d1160cd65d21076b1f640624663ad7b35f9c56 (patch)
treee6dd003c59002bb31a96f0dc357ee1f5ef84188d /tests
parent3823f29c05cb071cd3a595751543021a4f4cf382 (diff)
downloaddotty-35d1160cd65d21076b1f640624663ad7b35f9c56.tar.gz
dotty-35d1160cd65d21076b1f640624663ad7b35f9c56.tar.bz2
dotty-35d1160cd65d21076b1f640624663ad7b35f9c56.zip
More tests
Both some long overdue pos tests and more pickleOK tests
Diffstat (limited to 'tests')
-rw-r--r--tests/pos/flow.scala26
-rw-r--r--tests/pos/pickleOK/extmethods.scala8
-rw-r--r--tests/pos/pickleOK/hk.scala56
-rw-r--r--tests/pos/pickleOK/nameddefaults.scala63
-rw-r--r--tests/pos/pickleOK/selftypes.scala20
-rw-r--r--tests/pos/pickleOK/varargs.scala13
-rw-r--r--tests/pos/printTest.scala13
-rw-r--r--tests/pos/t5070.scala18
8 files changed, 217 insertions, 0 deletions
diff --git a/tests/pos/flow.scala b/tests/pos/flow.scala
new file mode 100644
index 000000000..76c0d372c
--- /dev/null
+++ b/tests/pos/flow.scala
@@ -0,0 +1,26 @@
+trait FlowOps[+Out] {
+ type Repr[+O] <: FlowOps[O]
+}
+
+trait Flow[-In, +Out] extends FlowOps[Out] {
+ override type Repr[+O] <: Flow[In, O]
+ def map[T](f: Out => T): Repr[T] /* workaround: expand alias Flow[In, T] */
+}
+
+class Test {
+ def slowFlow: Unit = {
+ (null: Flow[String, String])
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b)
+ .map(b => b) // takes an age to compile
+ }
+}
diff --git a/tests/pos/pickleOK/extmethods.scala b/tests/pos/pickleOK/extmethods.scala
new file mode 100644
index 000000000..3a0f8761c
--- /dev/null
+++ b/tests/pos/pickleOK/extmethods.scala
@@ -0,0 +1,8 @@
+package extMethods
+
+trait That1[A]
+class T[A, This <: That1[A]] extends AnyVal {
+ self: This =>
+ var next: This = _
+ final def loop(x: This, cnt: Int): Int = loop(x, cnt + 1)
+}
diff --git a/tests/pos/pickleOK/hk.scala b/tests/pos/pickleOK/hk.scala
new file mode 100644
index 000000000..9fdaf94f6
--- /dev/null
+++ b/tests/pos/pickleOK/hk.scala
@@ -0,0 +1,56 @@
+import language.higherKinds
+
+object hk0 {
+
+ abstract class Base {
+ type Rep[T]
+ val strRep: Rep[String]
+ }
+
+ class Sub extends Base {
+ type Rep[T] = T
+ val strRep = "abc"
+ val sr: Rep[String] = ""
+ }
+
+ abstract class Functor[F[_]] {
+ def map[A, B](f: A => B): F[A] => F[B]
+ }
+ val ml: Functor[List] = ???
+ val mx = ml
+ val mm: (Int => Boolean) => List[Int] => List[Boolean] = mx.map
+}
+
+object higherKinded {
+
+ type Untyped = Null
+
+ class Tree[-T >: Untyped] {
+ type ThisType[-U >: Untyped] <: Tree[U]
+ def withString(s: String): ThisType[String] = withString(s)
+ }
+
+ class Ident[-T >: Untyped] extends Tree[T] {
+ type ThisType[-U] = Ident[U]
+ }
+
+ val id = new Ident[Integer]
+
+ val y = id.withString("abc")
+
+ val z: Ident[String] = y
+
+ val zz: tpd.Tree = y
+
+ abstract class Instance[T >: Untyped] {
+ type Tree = higherKinded.Tree[T]
+ }
+
+ object tpd extends Instance[String]
+
+ def transform(tree: Tree[String]) = {
+ val tree1 = tree.withString("")
+ tree1: Tree[String]
+ }
+
+}
diff --git a/tests/pos/pickleOK/nameddefaults.scala b/tests/pos/pickleOK/nameddefaults.scala
new file mode 100644
index 000000000..671f14a07
--- /dev/null
+++ b/tests/pos/pickleOK/nameddefaults.scala
@@ -0,0 +1,63 @@
+object nameddefaults {
+
+ def foo(first: Int, second: Int = 2, third: Int = 3) = first + second
+
+ var x = 1
+ var y = 2
+
+ foo(1, 2, 3)
+
+ foo(1, 2)
+
+ foo(1)
+
+ // named and missing arguments
+
+ foo(first = 1, second = 3)
+
+ foo(second = 3, first = 1)
+
+ foo(first = 2, third = 3)
+
+ foo(2, third = 3)
+
+ // same but with non-idempotent expressions
+
+ foo(first = x, second = y)
+
+ foo(second = x, first = y)
+
+ foo(first = x, third = y)
+
+ foo(x, third = y)
+
+// The same thing, but for classes
+
+ class C(first: Int, second: Int = 2, third: Int = 3) {}
+
+ new C(1, 2, 3)
+
+ new C(1, 2)
+
+ new C(1)
+
+ // named and missing arguments
+
+ new C(first = 1, second = 3)
+
+ new C(second = 3, first = 1)
+
+ new C(first = 2, third = 3)
+
+ new C(2, third = 3)
+
+ // same but with non-idempotent expressions
+
+ new C(first = x, second = y)
+
+ new C(second = x, first = y)
+
+ new C(first = x, third = y)
+
+
+}
diff --git a/tests/pos/pickleOK/selftypes.scala b/tests/pos/pickleOK/selftypes.scala
new file mode 100644
index 000000000..243405f77
--- /dev/null
+++ b/tests/pos/pickleOK/selftypes.scala
@@ -0,0 +1,20 @@
+object selftypes {
+
+ trait A { self: AB =>
+
+ type AA = List[this.BX]
+
+ class AX
+
+ }
+
+ trait B { self: AB =>
+
+ type BB = AA
+
+ class BX
+ }
+
+ class AB extends A with B
+
+} \ No newline at end of file
diff --git a/tests/pos/pickleOK/varargs.scala b/tests/pos/pickleOK/varargs.scala
new file mode 100644
index 000000000..3739636b8
--- /dev/null
+++ b/tests/pos/pickleOK/varargs.scala
@@ -0,0 +1,13 @@
+object varargs {
+ List(1, 2, 3)
+ def g(x: Int*) = x.length
+ g(1, 2, 3, 4)
+ val x = if (true) 1 else 2
+ def foo[T](x: T, y: T): T = x
+ foo(1, 2)
+ val xs = 1 :: 2 :: Nil
+ g(xs: _*)
+ g(Nil: _*)
+ g(1)
+ g()
+} \ No newline at end of file
diff --git a/tests/pos/printTest.scala b/tests/pos/printTest.scala
new file mode 100644
index 000000000..81730f82b
--- /dev/null
+++ b/tests/pos/printTest.scala
@@ -0,0 +1,13 @@
+// tests printing functionality
+
+class C[X](x: Int, val y: String) {
+
+}
+
+object test extends C[String](1, "") {
+
+ new C[Int](1, "") {}
+
+ def foo(x: C[Int]) = new C[String](1, "") {}
+
+}
diff --git a/tests/pos/t5070.scala b/tests/pos/t5070.scala
new file mode 100644
index 000000000..c236b4f9e
--- /dev/null
+++ b/tests/pos/t5070.scala
@@ -0,0 +1,18 @@
+trait Web {
+ type LocalName
+}
+trait Companion1[A]
+trait WebDSL[W <: Web] {
+ trait LocalNameCompanion extends Companion1[W#LocalName] {
+ type A = String
+ }
+ implicit val LocalName: LocalNameCompanion
+}
+object Test {
+ def t[W <: Web](implicit webDSL: WebDSL[W]): Unit = {
+ import webDSL._
+ implicitly[LocalNameCompanion] // succeeds
+ implicitly[Companion1[W#LocalName]] // fails
+ }
+}
+