diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-03-24 09:37:34 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-03-24 09:37:34 +1000 |
commit | 40e08ea29e754b3cdd2f81339f1fc6ce0cda1107 (patch) | |
tree | 77862a96e6c53401059b25ae2da2bda74b5e7ae1 /test/files | |
parent | 88d4c15dfe4862b6d73fe54f00da5f2ea075b3f5 (diff) | |
parent | d0181ab3810f1e063b33e79b43f183a098de2aab (diff) | |
download | scala-40e08ea29e754b3cdd2f81339f1fc6ce0cda1107.tar.gz scala-40e08ea29e754b3cdd2f81339f1fc6ce0cda1107.tar.bz2 scala-40e08ea29e754b3cdd2f81339f1fc6ce0cda1107.zip |
Merge pull request #4389 from retronym/topic/jesper
Resurrect a test for type inference
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/pos/jesper.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/files/pos/jesper.scala b/test/files/pos/jesper.scala new file mode 100644 index 0000000000..82623e4a24 --- /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) + } + + 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 +} |