Skip to content

Very bizarre quote bug #7381

@alehander92

Description

@alehander92

One of the strangest bugs I've seen with Nim

import macros

macro a*: untyped =
  let name = newLit("name")
  result = quote:
    var b {.importc: `name`.}: int
  echo result.treerepr

a()
VarSection
  IdentDefs
    PragmaExpr
      Sym "b"
      Pragma
        ExprColonExpr
          Ident ident"importc"
          Ident ident"2"
    Sym "int"
    Empty

You can see instead of a string, we get ident 2 for importc

If you add more importc with quote, you get 3 etc

So I guess it's some kind of index instead of node issue

obviously one can use constant for now ( @zah gave me a workaround:)

import macros

macro a*: untyped =
  let name = newLit("name")
  let x = ident("x")
  result = quote:
    const `x` = `name`
    var b {.importc: x.}: int
  echo result.treerepr

a()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions