diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-02 14:08:32 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-02 14:08:32 -0700 |
commit | 4a627e7f279231853f361bbd31032642eabe565c (patch) | |
tree | 7e753dd628070da1fe43e12ed68ab948a2fbeb82 /test/files/run | |
parent | 13cf0481d2f584e464216b59eb73e33881d91bc6 (diff) | |
parent | 49f50727944a478bc5d10ad0658437286f47e422 (diff) | |
download | scala-4a627e7f279231853f361bbd31032642eabe565c.tar.gz scala-4a627e7f279231853f361bbd31032642eabe565c.tar.bz2 scala-4a627e7f279231853f361bbd31032642eabe565c.zip |
Merge pull request #2483 from adriaanm/merge-2.10.x
Merge 2.10.x
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 + +} |