Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

type mismatch from if statements #36

Open
Dolu1990 opened this issue Dec 15, 2017 · 0 comments
Open

type mismatch from if statements #36

Dolu1990 opened this issue Dec 15, 2017 · 0 comments

Comments

@Dolu1990
Copy link

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 :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant