nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
279 stars 39 forks source link

Variables in `{.compileTime.}` cannot be captured if the capturing closure is nested twice #1425

Closed alaviss closed 3 months ago

alaviss commented 3 months ago

Example

proc foo() {.compileTime.} =
  var x = 0

  proc bar() =
    proc foobar() =
      x = 1

    foobar()

  bar()

static: foo()

Actual Output

test.nim(6, 7) Error: 'x' is inaccesible because run-time values cannot be captured in a compile-time context

Additional Information

zerbina commented 3 months ago

The example code not working is deliberate, although for no good nor principled reason -- I'll remove the arbitrary restriction.