Skip to content

Commit 40e08ea

Browse files
committed
Merge pull request scala#4389 from retronym/topic/jesper
Resurrect a test for type inference
2 parents 88d4c15 + d0181ab commit 40e08ea

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/files/pos/jesper.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
object Pair {
2+
sealed trait Pair {
3+
type First
4+
type Second <: Pair
5+
}
6+
7+
case class End() extends Pair {
8+
type First = Nothing
9+
type Second = End
10+
11+
def ::[T](v : T) : Cons[T, End] = Cons(v, this)
12+
}
13+
14+
object End extends End()
15+
16+
final case class Cons[T1, T2 <: Pair](_1 : T1, _2 : T2) extends Pair {
17+
type First = T1
18+
type Second = T2
19+
20+
def ::[T](v : T) : Cons[T, Cons[T1, T2]] = Cons(v, this)
21+
def find[T](implicit finder : Cons[T1, T2] => T) = finder(this)
22+
}
23+
24+
implicit def findFirst[T1, T2 <: Pair] : Cons[T1, T2] => T1 = (p : Cons[T1, T2]) => p._1
25+
implicit def findSecond[T, T1, T2 <: Pair](implicit finder : T2 => T) : Cons[T1, T2] => T = (p : Cons[T1, T2]) => finder(p._2)
26+
27+
val p : Cons[Int, Cons[Boolean, End]] = 10 :: false :: End
28+
// val x : Boolean = p.find[Boolean](findSecond(findFirst))
29+
val x2 : Boolean = p.find[Boolean] // Doesn't compile
30+
}

0 commit comments

Comments
 (0)