Skip to content

Backticked vars misinterpreted by quote do: when creating pragmas #9745

@genotrance

Description

@genotrance

I'm using macros to create types with quote do: but added pragmas are not working correctly since backticked variables are interpreted incorrectly.

Example

import macros

var
  typ {.compiletime.} = "struct ABC"
  name {.compiletime.} = "ABC".newIdentNode()

macro abc(): untyped =
  result = newNimNode(nnkStmtList)

  result.add(quote do:
    type `name` {.importc: `typ`.} = object
  )

  echo result.repr

abc()

Current Output

type
  ABC {.importc: 3.} = object

Expected Output

type
  ABC {.importc: "struct ABC".} = object

Note that name is interpreted correctly, only contents in side the pragma section are misinterpreted. If you add more elements - e.g. header or something else, you get numbers again.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions