Skip to content

Passing $ to a typed param of a macro yields a single nnkSym instead of a nnkClosedSymChoice #12831

@liquidev

Description

@liquidev

Because $ is overloaded, I would expect an nnkClosedSymChoice to be returned.

Example

import macros

macro dumpRepr(x: typed): untyped =
  result = newLit(x.treeRepr & "\n")
echo dumpRepr(`$`)

Current Output

Sym "$"

Expected Output

ClosedSymChoice
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"
  Sym "$"

Additional Information

  • dumpRepr(typeof `$`) works, but wraps the node in an nnkTypeOfExpr
  • This issue is a problem for euwren, since you can't wrap stringifying procs without using a wrapper proc
$ nim -v
Nim Compiler Version 1.0.4 [Linux: amd64]
Compiled at 2019-11-27
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: c8998c498f5e2a0874846eb31309e1d1630faca6
active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions