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

nim v0.13.0 breaks symbol lookup in quote block #3744

Closed
jxy opened this issue Jan 19, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@jxy
Copy link
Contributor

commented Jan 19, 2016

The following code used to work.

import macros
macro t(): stmt =
  return quote do:
    proc tp(): int =
      result = 1
t()

Nim v0.13.0 seems to think the "result" in the quote block is for the macro "t", and gives the following error

t.nim(6, 2) template/generic instantiation from here
t.nim(5, 16) Error: type mismatch: got (int literal(1)) but expected 'NimNode'
@Araq

This comment has been minimized.

Copy link
Member

commented Jan 19, 2016

Interesting. Does 0.12.0 work with this?

@Araq Araq added the Regression label Jan 19, 2016

@Xe

This comment has been minimized.

Copy link

commented Jan 19, 2016

0.12.0 gets:

➜  nim c -r i3744.nim                                                             
Hint: system [Processing]
Hint: i3744 [Processing]
Hint: macros [Processing]
i3744.nim(6, 2) template/generic instantiation from here
i3744.nim(5, 16) Error: type mismatch: got (int literal(1)) but expected 'NimNode'
@jxy

This comment has been minimized.

Copy link
Contributor Author

commented Jan 19, 2016

Here is a changed example that works in 0.12.0, but fails in 0.13.0. It is a simplified version of my code that writes macros inside macros for calling bindSym and declaredInScope.

import macros
macro t(): stmt =
  return quote do:
    macro tp(): stmt =
      result = newCall("echo", newIntLitNode(1))
    tp()
t()

0.13.0 fails with:

t.nim(7, 2) template/generic instantiation from here
t.nim(5, 7) Error: illegal capture 'result'
@Araq

This comment has been minimized.

Copy link
Member

commented Jun 6, 2016

Sorry I cannot fix this for the upcoming release either but here is a good workaround:

import macros
macro t(): stmt =
  template vooo() {.dirty.} =
    macro tp(): stmt =
      result = newCall("echo", newIntLitNode(1))
    tp()
  return getAst(vooo())
t()
@Araq

This comment has been minimized.

Copy link
Member

commented Nov 18, 2017

Another workaround:

import macros
macro t(): stmt =
  template tmp() {.dirty.} =
    proc tp(): int =
      result = 1

  return getAst(tmp())
t()

@Araq Araq added the Low Priority label Nov 18, 2017

@Araq Araq closed this in 2ccc9db Jan 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.