Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Unexpected gensym in block

Open iffy opened this issue 4 years ago • 1 comments
trafficstars

When my macro is used in a block, the identifier for my object is suffixed with some numbers (e.g. _4855001) but I'm not expecting that. Compare Bob with Another_4855001 below:

Example

import macros

macro thing(name: static[string]) =
  result = newStmtList(
    nnkTypeSection.newTree(
      nnkTypeDef.newTree(
        ident(name),
        newEmptyNode(),
        nnkObjectTy.newTree(
          newEmptyNode(),
          newEmptyNode(),
          nnkRecList.newTree(
          )
        )
      )
    ),
  )

template foo(name: string): untyped =
  thing(name)

expandMacros:
  foo("Bob")

block:
  expandMacros:
    foo("Another")

Current Output

$ nim c --hints:off -r /tmp/samp.nim 

type
  Bob = object
  

type
  Another_4855001 = object

Expected Output

$ nim c --hints:off -r /tmp/samp.nim 

type
  Bob = object
  

type
  Another = object

Additional Information

$ nim --version
Nim Compiler Version 1.4.0 [MacOSX: amd64]
Compiled at 2020-10-16
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 018ae963ba83934a68d815c3c1c44c06e8ec6178
active boot switches: -d:release

iffy avatar Nov 24 '20 16:11 iffy