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

Unable to have array of NimNodes declared with const #7317

Open
PMunch opened this issue Mar 9, 2018 · 4 comments
Open

Unable to have array of NimNodes declared with const #7317

PMunch opened this issue Mar 9, 2018 · 4 comments
Labels
Error Messages VM see also `const` label

Comments

@PMunch
Copy link
Contributor

PMunch commented Mar 9, 2018

While trying to create a mapping table from strings to internal types for use in a macro I noticed I got weird errors when trying to have NimNodes in a const array:

static:
  let testArr = [parseExpr("int"), parseExpr("float")]
  const testArr2 = [parseExpr("int"), parseExpr("float")]

  echo testArr[0]
  echo testArr2[0]

This creates an error "Error: cannot generate VM code for int" for the second echo statement. Removing the echo statement makes it work fine, even with the declaration of the const. The let works fine.

@Yardanico
Copy link
Collaborator

Maybe it doesn't make sense to make a compile-time const?

@PMunch
Copy link
Contributor Author

PMunch commented Mar 9, 2018

Well doing it like this:

const test2 = [parseExpr("int"), parseExpr("float")]
static:
  echo treeRepr(test2[0])

or like this

const test2 = [parseExpr("int"), parseExpr("float")]
echo treeRepr(test2[0])

crashes the compiler with the error

lib/core/macros.nim(377, 1) Error: internal error: expr(nkIdent); unknown node kind
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>

@andreaferretti
Copy link
Collaborator

well, just use let inside the static block. It is static, it will not be there at runtime

@PMunch
Copy link
Contributor Author

PMunch commented Mar 14, 2018

Yeah I know how to work around it, but at the very least this should throw an better error. Or in the case of the compiler crashes an actual error instead.

@timotheecour timotheecour added the VM see also `const` label label Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Messages VM see also `const` label
Projects
None yet
Development

No branches or pull requests

4 participants