nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

Renderer does not use accent quotes on keyword identifiers #20180

Open deech opened 2 years ago

deech commented 2 years ago

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

metagn commented 2 years ago

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.

deech commented 2 years ago

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.