diff options
author | Martin Odersky <odersky@gmail.com> | 2014-06-18 18:20:14 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-06-18 18:21:07 +0200 |
commit | 7f721438b5bccc8ca9dd68cef273c8cac8199e1a (patch) | |
tree | a619fb770fee578354c7fca1f1c30c68f0d542d0 /tests/pos | |
parent | 388d9a889c6929699e879a307dc80145b906390a (diff) | |
download | dotty-7f721438b5bccc8ca9dd68cef273c8cac8199e1a.tar.gz dotty-7f721438b5bccc8ca9dd68cef273c8cac8199e1a.tar.bz2 dotty-7f721438b5bccc8ca9dd68cef273c8cac8199e1a.zip |
Handling higher-kinded types with lambdas
Switch to the new scheme where higher-kinded types (and also some polymorphic
type aliases) are represented as instances of Lambda traits.
Diffstat (limited to 'tests/pos')
-rw-r--r-- | tests/pos/apply-equiv.scala | 14 | ||||
-rw-r--r-- | tests/pos/collections.scala | 2 | ||||
-rw-r--r-- | tests/pos/hk.scala | 41 | ||||
-rw-r--r-- | tests/pos/lookuprefined.scala | 8 | ||||
-rw-r--r-- | tests/pos/partialApplications.scala | 13 | ||||
-rw-r--r-- | tests/pos/polyalias.scala | 26 | ||||
-rw-r--r-- | tests/pos/refinedSubtyping.scala | 19 | ||||
-rw-r--r-- | tests/pos/t0654.scala | 5 | ||||
-rw-r--r-- | tests/pos/t1236.scala | 2 | ||||
-rw-r--r-- | tests/pos/t2994.scala | 35 |
10 files changed, 153 insertions, 12 deletions
diff --git a/tests/pos/apply-equiv.scala b/tests/pos/apply-equiv.scala new file mode 100644 index 000000000..f53b8b5ab --- /dev/null +++ b/tests/pos/apply-equiv.scala @@ -0,0 +1,14 @@ +class Test { + + class Lambda { type Arg; type Apply } + + type T1 = (Lambda { type Arg = Int } { type Apply = List[Arg] }) # Apply + type T2 = List[Int] + + var x: T1 = _ + var y: T2 = _ + + x = y + y = x + +} diff --git a/tests/pos/collections.scala b/tests/pos/collections.scala index 535e4b542..08c3010c8 100644 --- a/tests/pos/collections.scala +++ b/tests/pos/collections.scala @@ -31,6 +31,6 @@ object collections { (ints2, chrs).zipped foreach do2 val xs = List(List(1), List(2), List(3)).iterator - println(xs.flatten) + println(/*scala.collection.TraversableOnce.flattenTraversableOnce*/(xs).flatten) } diff --git a/tests/pos/hk.scala b/tests/pos/hk.scala index f2f10bbfb..461c6e386 100644 --- a/tests/pos/hk.scala +++ b/tests/pos/hk.scala @@ -1,34 +1,55 @@ import language.higherKinds +object hk0 { + + class Base { + type Rep[T] + val strRep: Rep[String] + } + + class Sub extends Base { + type Rep[T] = T + val strRep = "abc" + val sr: Rep[String] = "" + } + + 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("") + val tree1 = tree.withString("") tree1: Tree[String] } diff --git a/tests/pos/lookuprefined.scala b/tests/pos/lookuprefined.scala new file mode 100644 index 000000000..f7e7f7337 --- /dev/null +++ b/tests/pos/lookuprefined.scala @@ -0,0 +1,8 @@ +class C { type T; type U } + +trait Test { + + val x: (C { type U = T } { type T = String }) # U + val y: String = x + +} diff --git a/tests/pos/partialApplications.scala b/tests/pos/partialApplications.scala new file mode 100644 index 000000000..b68c4b945 --- /dev/null +++ b/tests/pos/partialApplications.scala @@ -0,0 +1,13 @@ +object Test { + + type Histogram = Map[_, Int] + + type StringlyHistogram = Histogram[_ >: String] + + val xs: Histogram[String] = Map[String, Int]() + + val ys: StringlyHistogram[String] = xs + + val zs: StringlyHistogram = xs + +} diff --git a/tests/pos/polyalias.scala b/tests/pos/polyalias.scala new file mode 100644 index 000000000..07bb241f0 --- /dev/null +++ b/tests/pos/polyalias.scala @@ -0,0 +1,26 @@ + +object Test { + + type S = scala.Predef.Set + + val z: S = ??? + + + type Pair[T] = (T, T) + val x = (1, 2) + val xx: Pair[Int] = x + val xxx = xx + + type Config[T] = (T => T, String) + + val y = ((x: String) => x, "a") + val yy: Config[String] = y + val yyy = yy + + type RMap[K, V] = Map[V, K] + type RRMap[KK, VV] = RMap[VV, KK] + + val rm: RMap[Int, String] = Map[String, Int]() + val rrm: RRMap[Int, String] = Map[Int, String]() + +} diff --git a/tests/pos/refinedSubtyping.scala b/tests/pos/refinedSubtyping.scala new file mode 100644 index 000000000..e97d2a264 --- /dev/null +++ b/tests/pos/refinedSubtyping.scala @@ -0,0 +1,19 @@ +class Test { + + class C { type T; type Coll } + + type T1 = C { type T = Int } + + type T11 = T1 { type Coll = Set[Int] } + + type T2 = C { type Coll = Set[T] } + + type T22 = T2 { type T = Int } + + var x: T11 = _ + var y: T22 = _ + + x = y + y = x + +} diff --git a/tests/pos/t0654.scala b/tests/pos/t0654.scala new file mode 100644 index 000000000..0d0f2f7de --- /dev/null +++ b/tests/pos/t0654.scala @@ -0,0 +1,5 @@ +object Test { + class Foo[T] + type C[T] = Foo[_ <: T] // error: parameter type T of type alias does not appear as type argument of the aliased class Foo + val a: C[AnyRef] = new Foo[AnyRef] +} diff --git a/tests/pos/t1236.scala b/tests/pos/t1236.scala index a84cad0fb..fa1ab8c0f 100644 --- a/tests/pos/t1236.scala +++ b/tests/pos/t1236.scala @@ -10,5 +10,5 @@ object T { def foo[F[_]](q:(String,String)) = "hello" def foo[F[_]](e: Empty[F]) = "world" - val x = foo[List](ListEmpty) + val x = foo(ListEmpty) } diff --git a/tests/pos/t2994.scala b/tests/pos/t2994.scala new file mode 100644 index 000000000..c7421c42a --- /dev/null +++ b/tests/pos/t2994.scala @@ -0,0 +1,35 @@ +object Naturals { + trait NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] <: NAT + type v = a[SUCC, ZERO] + } + final class ZERO extends NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] = z + } + final class SUCC[n <: NAT] extends NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]] + } + type _0 = ZERO + type _1 = SUCC[_0] + type _2 = SUCC[_1] + type _3 = SUCC[_2] + type _4 = SUCC[_3] + type _5 = SUCC[_4] + type _6 = SUCC[_5] + + + // crashes scala-2.8.0 beta1 + trait MUL[n <: NAT, m <: NAT] extends NAT { + trait curry[n[_, _], s[_]] { type f[z <: NAT] = n[s, z] } + type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z] + } + +} + +object Test { + trait Bar[X[_]] + trait Baz[S[_] <: Bar[S]] { + type Apply[T] + } + trait Foo[V[_] <: Bar[V]] extends Bar[Baz[V]#Apply] +} |