Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #12740 #12774

Merged
merged 4 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions compiler/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ proc lsub(g: TSrcGen; n: PNode): int =
result = lcomma(g, n, 0, - 3)
if n[^2].kind != nkEmpty: result = result + lsub(g, n[^2]) + 2
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 nkChckRange64: result = len("chckRange64") + 2 + lcomma(g, n)
of nkChckRange: result = len("chckRange") + 2 + lcomma(g, n)
Expand Down Expand Up @@ -1119,12 +1123,17 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
putWithSpace(g, tkEquals, "=")
gsub(g, n[^1], c)
of nkVarTuple:
put(g, tkParLe, "(")
gcomma(g, n, 0, -3)
put(g, tkParRi, ")")
put(g, tkSpaces, Space)
putWithSpace(g, tkEquals, "=")
gsub(g, lastSon(n), c)
if n[^1].kind == nkEmpty:
put(g, tkParLe, "(")
gcomma(g, n, 0, -2)
put(g, tkParRi, ")")
else:
put(g, tkParLe, "(")
gcomma(g, n, 0, -3)
put(g, tkParRi, ")")
put(g, tkSpaces, Space)
putWithSpace(g, tkEquals, "=")
gsub(g, lastSon(n), c)
of nkExprColonExpr:
gsub(g, n, 0)
putWithSpace(g, tkColon, ":")
Expand Down
43 changes: 43 additions & 0 deletions tests/macros/tastrepr.nim
Original file line number Diff line number Diff line change
@@ -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)