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
import macros
funcflatty(dst, src: NimNode): NimNode=case src.kind
ofAtomicNodes:
result=newAssignment(copy(dst), copy(src))
of nnkStmtList, nnkStmtListExpr:
result=copyNimNode(src)
for idx in0..< src.len -1:
result.addcopy(src[idx])
result.addflatty(dst, src.last)
of nnkElifExpr, nnkElifBranch:
result=copyNimNode(src).add(copy src[0]):
flatty(dst, src[1])
of nnkElse, nnkElseExpr:
result=copyNimNode(src).add(flatty(dst, src[0]))
of nnkIfExpr, nnkIfStmt:
result=copyNimNode(src)
# if you instead build a new node, the issue doesn't happen# result = newNimNode(src.kind, src)for child in src.items:
result.addflatty(dst, child)
else:
error"unsupported node "&repr(src), src
macrorewriter(dst, src: typed): untyped=result=flatty(dst, src)
echoreprresultvar x: intrewriter(x):
iftrue: 1else: 0
Current Output
if true: x = 1
else:
x = 0
test.nim(35, 20) Error: expression 'x = 0' is of type 'int literal(1)' and has to be used (or discarded); start of expression here: test.nim(33, 1)
Additional Information
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-24
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 0f91b67f5c15328330f74a8769aed9961940aab2
active boot switches: -d:release -d:nimUseLinenoise
The text was updated successfully, but these errors were encountered:
Example
Current Output
Additional Information
The text was updated successfully, but these errors were encountered: