Nim icon indicating copy to clipboard operation
Nim copied to clipboard

`getImpl` ignores `nnkAccQuoted` identifier nodes

Open deech opened this issue 3 years ago • 2 comments

What happened?

If you have a proc where one of the argument names is quoted, getImpl ignores the backquotes:

import macros

proc p(`let`:int) = discard

static:
  echo bindSym("p").getImpl.repr

generates at compile time:

proc p(let: int) =
  discard

It should generate:

proc p(`let`:int) = 
  discard

Nim Version

Nim Compiler Version 1.7.1 [Linux: amd64] Compiled at 2022-06-15 Copyright (c) 2006-2022 by Andreas Rumpf

git hash: d33e1127666be23ad2dc879c2f89a41c179e2093

Current Standard Output Logs

No response

Expected Standard Output Logs

No response

Possible Solution

No response

Additional Information

No response

deech avatar Aug 08 '22 14:08 deech

let turns into a symbol node instead of a raw identifier, which is correct. This behavior is because of the AST rendering (repr); it would have to special case symbol nodes with names that need quotes and render them with quotes. A version of this behavior is already in the code, but it is limited (only checks the first char for special characters, see #19735) presumably to save performance.

metagn avatar Aug 09 '22 04:08 metagn

Then the backquotes should be part of the symbol, I consider an this an information losing bug which in this case turned valid into invalid code.

deech avatar Aug 09 '22 11:08 deech