tuple unpacking is not enforced in for loops anymore

This commit is contained in:
Araq 2011-06-15 10:15:32 +02:00
commit a15475f582
6 changed files with 40 additions and 4 deletions

View file

@ -447,14 +447,16 @@ proc semFor(c: PContext, n: PNode): PNode =
result = semForFields(c, n, call.sons[0].sym.magic)
else:
var iter = skipTypes(n.sons[length-2].typ, {tyGenericInst})
if iter.kind != tyTuple:
# length == 3 means that there is one for loop variable
# and thus no tuple unpacking:
if iter.kind != tyTuple or length == 3:
if length != 3: GlobalError(n.info, errWrongNumberOfVariables)
var v = newSymS(skForVar, n.sons[0], c)
v.typ = iter
n.sons[0] = newSymNode(v)
addDecl(c, v)
else:
if length-2 != sonsLen(iter):
if length-2 != sonsLen(iter):
GlobalError(n.info, errWrongNumberOfVariables)
for i in countup(0, length - 3):
var v = newSymS(skForVar, n.sons[i], c)

View file

@ -305,7 +305,10 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PTransNode =
proc transformYield(c: PTransf, n: PNode): PTransNode =
result = newTransNode(nkStmtList, n.info, 0)
var e = n.sons[0]
if skipTypes(e.typ, {tyGenericInst}).kind == tyTuple:
# c.transCon.forStmt.len == 3 means that there is one for loop variable
# and thus no tuple unpacking:
if skipTypes(e.typ, {tyGenericInst}).kind == tyTuple and
c.transCon.forStmt.len != 3:
e = skipConv(e)
if e.kind == nkPar:
for i in countup(0, sonsLen(e) - 1):