cps icon indicating copy to clipboard operation
cps copied to clipboard

Error calling continuation object/tuple field callback.

Open quantimnot opened this issue 9 months ago • 1 comments

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)

quantimnot avatar Mar 29 '25 11:03 quantimnot

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

disruptek avatar Sep 06 '25 15:09 disruptek