Skip to content

Commit d0181ab

Browse files
committed
Resurrect a test for type inference
This test was removed in ... when case class extension was disallowed. But the intent of the test was actually to exercise a path through type inference, described in `Infer#exprTypeArgs`. When I remove that special case, the test still fails: ``` test/files/pos/jesper.scala:29: error: No implicit view available from Pair.Cons[Int,Pair.Cons[Boolean,Pair.End]] => Boolean. val x2 : Boolean = p.find[Boolean] // Doesn't compile ^ one error found ``` This special case is important to understand when deciphering the inference in this program: ``` object Test { trait Cov[+A] def cov[A](implicit ev: Cov[A]): A = ??? implicit def covImp[A]: Cov[A] = ??? trait Inv[A] def inv[A](implicit ev: Inv[A]): A = ??? implicit def invImp[A]: Inv[A] = ??? trait Con[-A] def con[A](implicit ev: Con[A]): A = ??? implicit def conImp[A]: Con[A] = ??? cov : String // (Test.this.cov[String](Test.this.covImp[Nothing]): String); // (Test.this.cov[Nothing](Test.this.covImp[Nothing]): String) (or, without the special case in exprTypeArgs) inv : String // (Test.this.inv[Nothing](Test.this.invImp[Nothing]): String); con : String // (Test.this.con[Any](Test.this.conImp[Any]): String) } ```
1 parent fa33395 commit d0181ab

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)