This code gives a compilation error:
import scala.util.continuations._
object CTest {
def loop: Nothing = reset {
shift {c: (Unit => Nothing) => c()}
loop
}
def main(argv: Array[String]) {loop}
}
Error message:
error: type mismatch;
found : ((Unit) => Nothing) => (Unit) => Nothing
required: ((Unit) => B) => (Unit) => Nothing
But this code works as expected:
import scala.util.continuations._
object CTest {
def loop: Nothing = reset {
shift {c: (Unit => Any) => c.asInstanceOf[Unit => Nothing]()}
loop
}
def main(argv: Array[String]) {loop}
}
Question: why does the Scala compiler hate me continuations like Any => Nothing?
source
share