scala-continuations
scala-continuations copied to clipboard
type mismatch from if statements
Hi,
I'm building a hardware simulation API using scala continuation to get coroutine/green thread capabilities. So far so good, i just have a case with CPS that i don't understand, it could be a bug. There is an example where the funcA compilation is failing (bug/my miss-understanding ?). There is also a list of very similar cases where the compilation is passing :
import scala.util.continuations.cpsParam
def subFunc() : Unit@cpsParam[Unit,Unit] = {}
//Compilation fail on funcA, the error message is :
// Error:(13, 6) type mismatch;
// found : Unit
// required: Unit @scala.util.continuations.cpsParam[Unit,Unit]
// if(cond){
def funcA(cond : Boolean) : Unit@cpsParam[Unit,Unit] = {
if(cond){ //This is where the error is pointing
subFunc()
}
subFunc()
}
//Compilation OK
def funcB(cond : Boolean) : Unit@cpsParam[Unit,Unit] = {
val dummy = if(cond){
subFunc()
}
}
//Compilation OK
def funcC(cond : Boolean) : Unit@cpsParam[Unit,Unit] = {
val dummy = if(cond){
subFunc()
}
subFunc()
}
//Compilation OK
def funcD(cond : Boolean) : Unit@cpsParam[Unit,Unit] = {
if(cond){
subFunc()
} else {
subFunc()
}
}
//Compilation OK
def funcE(cond : Boolean) : Unit@cpsParam[Unit,Unit] = {
if(cond){ //This is where the error is pointing
???
}
subFunc()
}
Just to say, CPS is realy great to build DSL (see https://github.com/SpinalHDL/SpinalHDL/blob/sim/core/src/test/scala/landa/SimDemo.scala#L20), So far all alternatives that i have found were flawed or not performant enough :)