This commit is contained in:
Araq
2015-02-20 18:50:17 +01:00
parent 540f66cb09
commit aef7be2e79
2 changed files with 20 additions and 4 deletions

View File

@@ -19,12 +19,13 @@ type
proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
case n.kind
of nkEmpty..pred(nkIdent), succ(nkIdent)..nkNilLit: result = n
of nkIdent:
of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
of nkIdent, nkSym:
result = n
let ident = considerQuotedIdent(n)
var L = sonsLen(forLoop)
if c.replaceByFieldName:
if n.ident.id == forLoop[0].ident.id:
if ident.id == considerQuotedIdent(forLoop[0]).id:
let fieldName = if c.tupleType.isNil: c.field.name.s
elif c.tupleType.n.isNil: "Field" & $c.tupleIndex
else: c.tupleType.n.sons[c.tupleIndex].sym.name.s
@@ -32,7 +33,7 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
return
# other fields:
for i in ord(c.replaceByFieldName)..L-3:
if n.ident.id == forLoop[i].ident.id:
if ident.id == considerQuotedIdent(forLoop[i]).id:
var call = forLoop.sons[L-2]
var tupl = call.sons[i+1-ord(c.replaceByFieldName)]
if c.field.isNil:

View File

@@ -0,0 +1,15 @@
discard """
output: '''n
n'''
"""
# bug #1902
# This works.
for name, value in (n: "v").fieldPairs:
echo name
# This doesn't compile - "expression 'name' has no type (or is ambiguous)".
template wrapper: stmt =
for name, value in (n: "v").fieldPairs:
echo name
wrapper()