You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to store a NimNode in a container object, I found that my subsequent changes to the NimNode don't show up in other references to it.
This only happens if the NimNode originated from parseStmt or parseExpr, and only when storing the NimNode in a container (object, seq, etc.) or a global variable.
If you use newTree or quote do, the bug doesn't occur.
If you put the NimNode in a local variable or pass it as an argument, the bug doesn't occur.
Example
import macros
typeContainer=object
n: NimNodeprocaddBam(n: NimNode) =
n.addnewCall("echo", newLit("bam"))
var z {.compileTime.}: NimNodemacrotest() =#var a = newStmtList() # use this instead and the bug goes awayvar a =parseStmt("discard")
let c =Container(n:a)
let x = a
z = a
a.addnewCall("echo", newLit("foo")) # added
c.n.addnewCall("echo", newLit("bar")) # not added!
x.addnewCall("echo", newLit("baz")) # added
x.addBam() # added
z.addnewCall("echo", newLit("bat")) # not added!
a
test()
Current Output
foo
baz
bam
Expected Output
foo
bar
baz
bam
bat
Additional Information
I tested as far back as Nim 0.18.0, the behaviour still happens exactly as shown.
$ nim -v
Nim Compiler Version 1.2.0 [Windows: amd64]
Compiled at 2020-04-03
The text was updated successfully, but these errors were encountered:
When trying to store a NimNode in a container object, I found that my subsequent changes to the NimNode don't show up in other references to it.
This only happens if the NimNode originated from
parseStmt
orparseExpr
, and only when storing the NimNode in a container (object, seq, etc.) or a global variable.newTree
orquote do
, the bug doesn't occur.Example
Current Output
Expected Output
Additional Information
I tested as far back as Nim 0.18.0, the behaviour still happens exactly as shown.
The text was updated successfully, but these errors were encountered: