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
Definitely this bug gave me a lot of head scratching, because I was writing a macro that stored some backreferences to the ast in a seq. Turned out that all my references were useless, because they were secretly copies of the syntax tree at the time I created the references.
Fixing this bug could break a lot of code, that only works because of this misbehavior, but time doesn't make the bug easier to fix.
import macros
macrotestmacro*(): untyped=let innerStmtList =quotedo:
discardlet localLet = innerStmtList
var localVar = innerStmtList
let localArray = [innerStmtList,localLet]
var localSeq =newSeq[NimNode](0)
localSeq.add(innerStmtList)
localSeq.add(localLet)
# since NimNode is a ref type, and all seq type# and local variables only contain copies of the# references, this should get rid of the discard statement# everywhere, but it doesn't.
innerStmtList.del(0)
echo"# all represent the same value (OK) #"echo innerStmtList.treeRepr
echo localLet.treeRepr
echo localVar.treeRepr
echo"# secretly copied (totally not ok) ##"echo localArray[0].treeRepr
echo localArray[1].treeRepr
echo localSeq[0].treeRepr
echo localSeq[1].treeRepr
echo"#####################################"discarddiscardtestmacro()
output:
# all represent the same value (OK) #
StmtList
StmtList
StmtList
# secretly copied (totally not ok) ##
StmtList
DiscardStmt
Empty
StmtList
DiscardStmt
Empty
StmtList
DiscardStmt
Empty
StmtList
DiscardStmt
Empty
#####################################
expected:
# all represent the same value (OK) #
StmtList
StmtList
StmtList
# secretly copied (totally not ok) ##
StmtList
StmtList
StmtList
StmtList
#####################################
The text was updated successfully, but these errors were encountered:
@jxy It's hard to say, because honestly at the moment I don't know what your code want's to do since it has no comments nor any meaningful names for anything. I also don't know what you expect your code to behave.
Definitely this bug gave me a lot of head scratching, because I was writing a macro that stored some backreferences to the ast in a seq. Turned out that all my references were useless, because they were secretly copies of the syntax tree at the time I created the references.
Fixing this bug could break a lot of code, that only works because of this misbehavior, but time doesn't make the bug easier to fix.
output:
expected:
The text was updated successfully, but these errors were encountered: