This commit is contained in:
Araq 2015-02-20 18:50:17 +01:00
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 = proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
case n.kind case n.kind
of nkEmpty..pred(nkIdent), succ(nkIdent)..nkNilLit: result = n of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
of nkIdent: of nkIdent, nkSym:
result = n result = n
let ident = considerQuotedIdent(n)
var L = sonsLen(forLoop) var L = sonsLen(forLoop)
if c.replaceByFieldName: 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 let fieldName = if c.tupleType.isNil: c.field.name.s
elif c.tupleType.n.isNil: "Field" & $c.tupleIndex elif c.tupleType.n.isNil: "Field" & $c.tupleIndex
else: c.tupleType.n.sons[c.tupleIndex].sym.name.s else: c.tupleType.n.sons[c.tupleIndex].sym.name.s
@ -32,7 +33,7 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
return return
# other fields: # other fields:
for i in ord(c.replaceByFieldName)..L-3: 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 call = forLoop.sons[L-2]
var tupl = call.sons[i+1-ord(c.replaceByFieldName)] var tupl = call.sons[i+1-ord(c.replaceByFieldName)]
if c.field.isNil: 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()