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

Unexpected gensym in block #16118

Closed
iffy opened this issue Nov 24, 2020 · 1 comment · Fixed by #24028
Closed

Unexpected gensym in block #16118

iffy opened this issue Nov 24, 2020 · 1 comment · Fixed by #24028

Comments

@iffy
Copy link
Contributor

iffy commented Nov 24, 2020

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
@metagn
Copy link
Collaborator

metagn commented Aug 27, 2024

Fixed in #23969

metagn added a commit to metagn/Nim that referenced this issue Aug 29, 2024
@Araq Araq closed this as completed in fc853cb Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants