Skip to content

assigning indexed NimNode to tuple/object field copies #12457

@ghost

Description

Example

import macros

macro notBug(n: untyped): untyped =
  let node = n[0] # skip the nnkStmtList
  node[1] = newLit(2) # replace 0 with 2
  result = n

macro bug(n: untyped): untyped =
  let (node, ) = (n[0], )
  node[1] = newLit(2)
  # Another version using object:
  # type Holder = object
  #   val: NimNode
  # let node = Holder(val: n[0])
  # node.val[1] = newLit(2)
  result = n

var x = notBug: 0 * 2
var y = bug: 0 * 2
echo x
echo y

Current Output

4
0

Expected Output

4
4

Additional Information

Doesn't seem to be a regression.

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