* fix #12740 * A different kind of a hack * proper fix * fix typo
This commit is contained in:
parent
3383985c44
commit
b0c06aa711
2 changed files with 59 additions and 7 deletions
|
|
@ -451,7 +451,11 @@ proc lsub(g: TSrcGen; n: PNode): int =
|
||||||
result = lcomma(g, n, 0, - 3)
|
result = lcomma(g, n, 0, - 3)
|
||||||
if n[^2].kind != nkEmpty: result = result + lsub(g, n[^2]) + 2
|
if n[^2].kind != nkEmpty: result = result + lsub(g, n[^2]) + 2
|
||||||
if n[^1].kind != nkEmpty: result = result + lsub(g, n[^1]) + 3
|
if n[^1].kind != nkEmpty: result = result + lsub(g, n[^1]) + 3
|
||||||
of nkVarTuple: result = lcomma(g, n, 0, - 3) + len("() = ") + lsub(g, lastSon(n))
|
of nkVarTuple:
|
||||||
|
if n[^1].kind == nkEmpty:
|
||||||
|
result = lcomma(g, n, 0, - 2) + len("()")
|
||||||
|
else:
|
||||||
|
result = lcomma(g, n, 0, - 3) + len("() = ") + lsub(g, lastSon(n))
|
||||||
of nkChckRangeF: result = len("chckRangeF") + 2 + lcomma(g, n)
|
of nkChckRangeF: result = len("chckRangeF") + 2 + lcomma(g, n)
|
||||||
of nkChckRange64: result = len("chckRange64") + 2 + lcomma(g, n)
|
of nkChckRange64: result = len("chckRange64") + 2 + lcomma(g, n)
|
||||||
of nkChckRange: result = len("chckRange") + 2 + lcomma(g, n)
|
of nkChckRange: result = len("chckRange") + 2 + lcomma(g, n)
|
||||||
|
|
@ -1119,6 +1123,11 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
putWithSpace(g, tkEquals, "=")
|
putWithSpace(g, tkEquals, "=")
|
||||||
gsub(g, n[^1], c)
|
gsub(g, n[^1], c)
|
||||||
of nkVarTuple:
|
of nkVarTuple:
|
||||||
|
if n[^1].kind == nkEmpty:
|
||||||
|
put(g, tkParLe, "(")
|
||||||
|
gcomma(g, n, 0, -2)
|
||||||
|
put(g, tkParRi, ")")
|
||||||
|
else:
|
||||||
put(g, tkParLe, "(")
|
put(g, tkParLe, "(")
|
||||||
gcomma(g, n, 0, -3)
|
gcomma(g, n, 0, -3)
|
||||||
put(g, tkParRi, ")")
|
put(g, tkParRi, ")")
|
||||||
|
|
|
||||||
43
tests/macros/tastrepr.nim
Normal file
43
tests/macros/tastrepr.nim
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
var data = @[(1, "one"), (2, "two")]
|
||||||
|
for (i, d) in pairs(data):
|
||||||
|
discard
|
||||||
|
for i, d in pairs(data):
|
||||||
|
discard
|
||||||
|
for i, (x, y) in pairs(data):
|
||||||
|
discard
|
||||||
|
var (a, b) = (1, 2)
|
||||||
|
|
||||||
|
var data = @[(1, "one"), (2, "two")]
|
||||||
|
for (i, d) in pairs(data):
|
||||||
|
discard
|
||||||
|
for i, d in pairs(data):
|
||||||
|
discard
|
||||||
|
for i, (x, y) in pairs(data):
|
||||||
|
discard
|
||||||
|
var (a, b) = (1, 2)
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
macro echoTypedRepr(arg: typed) =
|
||||||
|
result = newCall(ident"echo", newLit(arg.repr))
|
||||||
|
|
||||||
|
macro echoUntypedRepr(arg: untyped) =
|
||||||
|
result = newCall(ident"echo", newLit(arg.repr))
|
||||||
|
|
||||||
|
template echoTypedAndUntypedRepr(arg: untyped) =
|
||||||
|
echoTypedRepr(arg)
|
||||||
|
echoUntypedRepr(arg)
|
||||||
|
|
||||||
|
echoTypedAndUntypedRepr:
|
||||||
|
var data = @[(1,"one"), (2,"two")]
|
||||||
|
for (i, d) in pairs(data):
|
||||||
|
discard
|
||||||
|
for i, d in pairs(data):
|
||||||
|
discard
|
||||||
|
for i, (x,y) in pairs(data):
|
||||||
|
discard
|
||||||
|
var (a,b) = (1,2)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue