mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #1902
This commit is contained in:
@@ -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:
|
||||
|
||||
15
tests/fields/tfields_in_template.nim
Normal file
15
tests/fields/tfields_in_template.nim
Normal 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()
|
||||
Reference in New Issue
Block a user