Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: cannot evaluate at compile time when using var in a static: block inside a proc #8758

Open
timotheecour opened this issue Aug 24, 2018 · 1 comment
Labels
const `const x=expr` or `static: stmt`

Comments

@timotheecour
Copy link
Member

reduced from a more complex scenario:

template baz*() =
  var i = 0

proc foo2() =
  static:
    when defined(case1):
      # Error: cannot evaluate at compile time:
      var i = 0
    when defined(case2):
      # Error: cannot evaluate at compile time:
      baz()

static:
  when defined(case3):
    # ok
    var i = 0
  when defined(case4):
    # ok
    baz()

maybe related

timotheecour added a commit to timotheecour/Nim that referenced this issue Aug 24, 2018
timotheecour added a commit to timotheecour/Nim that referenced this issue Aug 24, 2018
timotheecour added a commit to timotheecour/Nim that referenced this issue Aug 24, 2018
@LemonBoy
Copy link
Contributor

LemonBoy commented Sep 7, 2018

Minimal test case:

proc foo() =
  static:
    var i = 42
    echo i

The problem here is that the static block is "transparent" and the whole body is semanticized as if it were part of the enclosing foo. This means that the compile-time variable i is generated with foo as symbol owner and that makes it impossible for the VM to recognize whether it's a CT variable or not.

The proposed solution is: let's push the outer module as owner.

CC @Araq

@ringabout ringabout added the const `const x=expr` or `static: stmt` label Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
const `const x=expr` or `static: stmt`
Projects
None yet
Development

No branches or pull requests

3 participants