Scala: compilation error when declaring a continuation of type Any => Nothing

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?

+3
source share
2 answers

It compiles if I specify arguments like:

shift[Unit, Nothing, Nothing] {c: (Unit => Nothing) => c()}

It seems to me that the compiler should conclude that Bthere is Nothing, but it is not.

+3
source

Nothing, . , Nothing, . , , , .

Java- void Unit Scala.

, , .

+1

All Articles