Skip to content

repr doesn't work with hex literals (and other repr bugs now fixed) #17292

@timotheecour

Description

@timotheecour

bugs

Example 1

when true:
  macro deb(a) =
    echo a.repr

  deb:
    let f = () => (discard)
    f()
    let x = 0xffffffffffffffff
    template fn(body: untyped): untyped = true
    doAssert(fn do: nonexistant)
    template foo(x, y) =
      x
      y
    foo:
      discard
    do:
      discard

Current Output

let f = () =>
  discard
f()
let x = 0xFFFFFFFF
template fn(body: untyped): untyped =
  true

doAssert(fn:
  nonexistant)
template foo(x, y) =
  x
  y

foo(
  discard ):
  discard

Expected Output

let f = () =>
  (discard)
f()
let x = 0xffffffffffffffff
template fn(body: untyped): untyped =
  true

doAssert(fn do: nonexistant)
template foo(x, y) =
  x
  y

foo:
  discard
do:
  discard

Example 2

repr doesn't work with nnkAccQuoted:

import macros
macro deb(a) =
  echo a.repr
deb:
  proc `=destroy`(a: Foo) = discard
  proc `'foo`(a: string): int = discard

prints:

proc `= destroy`(a: Foo) =
  discard

proc `' foo`(a: string): int =
  discard

the culprit is the spaces inserted here in renderer.nim:

  of nkAccQuoted:
    put(g, tkAccent, "`")
    if n.len > 0: gsub(g, n[0])
    for i in 1..<n.len:
      put(g, tkSpaces, Space)
      gsub(g, n[i])
    put(g, tkAccent, "`")

Example 3

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    AST RendererIssues related to the compiler turning AST back into Nim code as a string.Parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions