diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-03-26 09:39:01 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-03-27 00:16:27 +0100 |
commit | 8703e00b3876cad8750abf82949737cac8bde6fe (patch) | |
tree | 826668aa84f078e9e3e01275bec1c86ef631feb0 /test/files/run | |
parent | fcc22e22248992abffe2506ddef7c0f7c0b23044 (diff) | |
download | scala-8703e00b3876cad8750abf82949737cac8bde6fe.tar.gz scala-8703e00b3876cad8750abf82949737cac8bde6fe.tar.bz2 scala-8703e00b3876cad8750abf82949737cac8bde6fe.zip |
SI-7200 Test case for fixed type inference error.
Broken in 2.9.2 and 2.10.0, but working in 2.10.1
--- sandbox/2.10.0.log
+++ sandbox/2.10.1.log
def coflatMap[A >: Nothing <: Any, B >: Nothing <: Any](f: Test.Nel[A] => B): Test.Nel[A] => Test.Nel[B] = ((l: Test.Nel[A]) => Test.this.Nel.apply[B](f.apply(l), l.tail match {
case immutable.this.Nil => immutable.this.Nil
- case (hd: A, tl: List[A])scala.collection.immutable.::[A]((h @ _), (t @ _)) => {
- val r: Test.Nel[Nothing] = NelFoo.this.coflatMap[A, Nothing](f).apply(Test.this.Nel.apply[A](h, t));
+ case (hd: A, tl: List[A])scala.collection.immutable.::[?A1]((h @ _), (t @ _)) => {
+ val r: Test.Nel[B] = NelFoo.this.coflatMap[A, B](f).apply(Test.this.Nel.apply[A](h, t));
{
- <synthetic> val x$1: Nothing = r.head;
- r.tail.::[Nothing](x$1)
+ <synthetic> val x$1: B = r.head;
+ r.tail.::[B](x$1)
}
}
}))
b74c33eb86 represents the exact moment of progression. Comments
in pos/t7200b.scala, a minimal test that demonstrates the problem
without type constructors or code execution, pinpoint the line of
code responsible for the fix.
Incidentally, I'm currently on a train somewhere between Solothurn
and Biel, and am consequently without the power of scala-bisector.
Undeterred, and inspired by a line I saw in Skyfall last night
("sometimes the olds ways are better"), I just pulled off a two-hop
bisection. Take that, O(log N)!
The one remaining worry is the appearance of the type variable
?A1 in the output of -Xprint:typer for run/t7200.scala.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t7200.scala | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/files/run/t7200.scala b/test/files/run/t7200.scala new file mode 100644 index 0000000000..ba342df14d --- /dev/null +++ b/test/files/run/t7200.scala @@ -0,0 +1,34 @@ +import language.higherKinds + +object Test extends App { + + // Slice of comonad is where this came up + trait Foo[F[_]] { + def coflatMap[A, B](f: F[A] => B): F[A] => F[B] + } + + // A non-empty list + case class Nel[A](head: A, tail: List[A]) + + object NelFoo extends Foo[Nel] { + + // It appears that the return type for recursive calls is not inferred + // properly, yet no warning is issued. Providing a return type or + // type arguments for the recursive call fixes the problem. + + def coflatMap[A, B](f: Nel[A] => B) = // ok w/ return type + l => Nel(f(l), l.tail match { + case Nil => Nil + case h :: t => { + val r = coflatMap(f)(Nel(h, t)) // ok w/ type args + r.head :: r.tail + } + }) + } + + // Without a recursive call all is well, but with recursion we get a + // ClassCastException from Integer to Nothing + NelFoo.coflatMap[Int, Int](_.head + 1)(Nel(1, Nil)) // Ok + NelFoo.coflatMap[Int, Int](_.head + 1)(Nel(1, List(2))) // CCE + +} |