aboutsummaryrefslogtreecommitdiff
path: root/tests/untried/pos/typesafecons.scala
diff options
context:
space:
mode:
authorSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
committerSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
commit9ef5f6817688f814a3450126aa7383b0928e80a0 (patch)
tree5727a2f7f7fd665cefdb312af2785c692f04377c /tests/untried/pos/typesafecons.scala
parent194be919664447631ba55446eb4874979c908d27 (diff)
downloaddotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.gz
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.bz2
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.zip
add tests from scala/test/files/{pos,neg}
with explicit Unit return type
Diffstat (limited to 'tests/untried/pos/typesafecons.scala')
-rw-r--r--tests/untried/pos/typesafecons.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/untried/pos/typesafecons.scala b/tests/untried/pos/typesafecons.scala
new file mode 100644
index 000000000..524328016
--- /dev/null
+++ b/tests/untried/pos/typesafecons.scala
@@ -0,0 +1,30 @@
+object Pair {
+ sealed trait Pair {
+ type First
+ type Second <: Pair
+ }
+
+ 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
+}