mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #18104
(cherry picked from commit 1e9a3c438b)
This commit is contained in:
@@ -780,6 +780,24 @@ proc makeVarTupleSection(c: PContext, n, a, def: PNode, typ: PType, symkind: TSy
|
||||
proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||
var b: PNode
|
||||
result = copyNode(n)
|
||||
|
||||
# transform var x, y = 12 into var x = 12; var y = 12
|
||||
# bug #18104; transformation should be finished before templates expansion
|
||||
# TODO: move warnings for tuple here
|
||||
var transformed = copyNode(n)
|
||||
for i in 0..<n.len:
|
||||
var a = n[i]
|
||||
if a.kind == nkIdentDefs and a.len > 3 and a[^1].kind != nkEmpty:
|
||||
for j in 0..<a.len-2:
|
||||
var b = newNodeI(nkIdentDefs, a.info)
|
||||
b.add a[j]
|
||||
b.add a[^2]
|
||||
b.add copyTree(a[^1])
|
||||
transformed.add b
|
||||
else:
|
||||
transformed.add a
|
||||
let n = transformed
|
||||
|
||||
for i in 0..<n.len:
|
||||
var a = n[i]
|
||||
if c.config.cmd == cmdIdeTools: suggestStmt(c, a)
|
||||
|
||||
@@ -2,6 +2,7 @@ discard """
|
||||
output: "44"
|
||||
"""
|
||||
# Test the new variable declaration syntax
|
||||
import std/sequtils
|
||||
|
||||
var
|
||||
x = 0
|
||||
@@ -10,3 +11,9 @@ var
|
||||
|
||||
write(stdout, a)
|
||||
writeLine(stdout, b) #OUT 44
|
||||
|
||||
proc p() = # bug #18104
|
||||
var x, y = newSeqWith(10, newString(3))
|
||||
discard (x, y)
|
||||
|
||||
p()
|
||||
|
||||
Reference in New Issue
Block a user