cps
cps copied to clipboard
Error calling continuation object/tuple field callback.
import pkg/cps
var wait: Continuation
proc a(x: int): int {.cps: Continuation.} =
x * 2
type
Fn = proc (x: int): int {.cps: Continuation.}
Calc = object
fn: Fn
proc worksAsNormal(fn: Fn): int {.cps: Continuation.} =
fn(10)
proc workaround(c: Calc): int {.cps: Continuation.} =
let fn = c.fn
fn(10)
proc fails1(c: Calc): int {.cps: Continuation.} =
c.fn(10) #[tt.Error
^ attempting to call undeclared routine: 'fn']#
proc fails2(c: Calc): int {.cps: Continuation.} =
template fun(x): untyped = c.fn(x) #[tt.Error
^ attempting to call undeclared routine: 'fn']#
fun(10)
Haven't looked at the issues in awhile and just noticed this. It seems to be a compiler bug under mainline -- 2.0 and some devel branch of 2.2.2, at least. Here's a reduction which fails under mainline but not 'skull:
import cps
type
CC = proc () {.cps: Continuation.}
A = object
n: CC
proc nimland(a: A): int =
a.n()