nim-works / cps

Continuation-Passing Style for Nim 🔗

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: cps doesn't know how to rewrite this into assignment:

zevv opened this issue · comments

import cps

type
  C = Continuation
  P = object
    val: int

proc bar(c: C): C {.cpsMagic.} =      
  c

proc foo(p: P): int {.cps:C.} =
  bar()             
  p.val
       
echo foo(P())
/tmp/t.nim(13, 23) template/generic instantiation of `cps` from here
/tmp/t.nim(14, 3) template/generic instantiation of `cpsAsgn` from here
/tmp/t.nim(15, 4) Error: cps doesn't know how to rewrite this into assignment:
DotExpr
  Sym "p"
  Sym "val"

@alaviss is this a matter of exprs.assignTo (or futher up) understanding that the last expression in a proc that otherwise doesn't have mention of result is a return?

So the trick would be detecting that and then handling the case in exprs.filterExpr?