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

Is "internal error: environment misses ..." expected behavior when mixing ident with symbols? #11043

Open
bluenote10 opened this issue Apr 16, 2019 · 0 comments
Labels

Comments

@bluenote10
Copy link
Contributor

bluenote10 commented Apr 16, 2019

I would be interested in some clarification regarding RFC nim-lang/RFCs#44 (CC @mratsim): Is it by design that it is not possible to have a NimSym referring to a NimIdent?

Minimal example:

import macros

macro typedMacro(body: typed): untyped =
  result = newProc(
    ident "newTest",
    [newEmptyNode(), newIdentDefs(ident "x", ident "int")],
    body[0][6], # the original proc body
  )
  echo result.repr

# Basically the macro generate a proc `newTest` with exactly the same signature.
# However it uses a fresh ident to define `x`, but reuses the `x` symbol from the body.
typedMacro():
  proc test(x: int) =
    echo x

newTest(1) # interestingly the problem is only triggered IF we call the proc

The resulting AST shows the difference between ident and symbols:

ProcDef
  Ident "newTest"
  Empty
  Empty
  FormalParams
    Empty
    IdentDefs
      Ident "x"
      Ident "int"
      Empty
  Empty
  Empty
  Command
    Sym "echo"
    HiddenStdConv
      Empty
      Bracket
        HiddenCallConv
          Sym "$"
          Sym "x"

This currently errors with: Error: internal error: environment misses: x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants