diff options
author | Martin Odersky <odersky@gmail.com> | 2008-09-04 16:33:51 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2008-09-04 16:33:51 +0000 |
commit | 3e0cd7e7488477e60eb8d12ffeea1b3dc02433a5 (patch) | |
tree | 39e044e9c789277e68c89a72533088dc4190e8d7 /test/files/pos | |
parent | 743edeefd44939ada6e81c5936cc04f7c6601931 (diff) | |
download | scala-3e0cd7e7488477e60eb8d12ffeea1b3dc02433a5.tar.gz scala-3e0cd7e7488477e60eb8d12ffeea1b3dc02433a5.tar.bz2 scala-3e0cd7e7488477e60eb8d12ffeea1b3dc02433a5.zip |
now checking for volatile types.
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/jesper.scala | 30 | ||||
-rw-r--r-- | test/files/pos/typesafecons.scala | 30 |
2 files changed, 60 insertions, 0 deletions
diff --git a/test/files/pos/jesper.scala b/test/files/pos/jesper.scala new file mode 100644 index 0000000000..b2a027b0f2 --- /dev/null +++ b/test/files/pos/jesper.scala @@ -0,0 +1,30 @@ +object Pair { + sealed trait Pair { + type First + type Second <: Pair + } + + case class End extends Pair { + type First = Nothing + type Second = End + + def ::[T](v : T) : Cons[T, End] = Cons(v, this) + } + + case object End extends End + + final case class Cons[T1, T2 <: Pair](_1 : T1, _2 : T2) extends Pair { + type First = T1 + type Second = T2 + + def ::[T](v : T) : Cons[T, Cons[T1, T2]] = Cons(v, this) + def find[T](implicit finder : Cons[T1, T2] => T) = finder(this) + } + + implicit def findFirst[T1, T2 <: Pair] : Cons[T1, T2] => T1 = (p : Cons[T1, T2]) => p._1 + implicit def findSecond[T, T1, T2 <: Pair](implicit finder : T2 => T) : Cons[T1, T2] => T = (p : Cons[T1, T2]) => finder(p._2) + + val p : Cons[Int, Cons[Boolean, End]] = 10 :: false :: End +// val x : Boolean = p.find[Boolean](findSecond(findFirst)) + val x2 : Boolean = p.find[Boolean] // Doesn't compile +} diff --git a/test/files/pos/typesafecons.scala b/test/files/pos/typesafecons.scala new file mode 100644 index 0000000000..b2a027b0f2 --- /dev/null +++ b/test/files/pos/typesafecons.scala @@ -0,0 +1,30 @@ +object Pair { + sealed trait Pair { + type First + type Second <: Pair + } + + case class End extends Pair { + type First = Nothing + type Second = End + + def ::[T](v : T) : Cons[T, End] = Cons(v, this) + } + + case object End extends End + + final case class Cons[T1, T2 <: Pair](_1 : T1, _2 : T2) extends Pair { + type First = T1 + type Second = T2 + + def ::[T](v : T) : Cons[T, Cons[T1, T2]] = Cons(v, this) + def find[T](implicit finder : Cons[T1, T2] => T) = finder(this) + } + + implicit def findFirst[T1, T2 <: Pair] : Cons[T1, T2] => T1 = (p : Cons[T1, T2]) => p._1 + implicit def findSecond[T, T1, T2 <: Pair](implicit finder : T2 => T) : Cons[T1, T2] => T = (p : Cons[T1, T2]) => finder(p._2) + + val p : Cons[Int, Cons[Boolean, End]] = 10 :: false :: End +// val x : Boolean = p.find[Boolean](findSecond(findFirst)) + val x2 : Boolean = p.find[Boolean] // Doesn't compile +} |