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.54k stars 1.47k forks source link

Renderer doesn't escape/quote symbols when it should #19735

Open yglukhov opened 2 years ago

yglukhov commented 2 years ago
import macros

macro dumpRepr(u: typed) =
  echo repr u

template decl(a: untyped) =
  proc `a @ procName`(`a @ param`: int) = discard

dumpRepr:
  decl(hi)

Actual output:

proc hi@procName(a@param`gensym0: int) =
  discard

Expected output:

proc `hi@procName`(`a@param'`'gensym0`: int) =
  discard
$ nim -v
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-04-19
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: dc4cc2dca53e3772efb3654a4ddbbe8350d1db43
active boot switches: -d:release
ghost commented 2 years ago

I've briefly looked at the renderer, and it only seems to check the first character of the name to see if it should be quoted or not - https://github.com/nim-lang/Nim/blob/devel/compiler/renderer.nim#L971

It's possible to change this to check the whole string, not just the first character, although I'm not sure if it's the right approach.

metagn commented 2 years ago

This should not have a Codegen label