fixes #24339; underscores used with fields and fieldPairs (#24341)

fixes #24339
This commit is contained in:
ringabout
2025-02-27 23:48:15 +08:00
committed by GitHub
parent b421d0f8ee
commit 7ecb35115b
2 changed files with 9 additions and 2 deletions

View File

@@ -36,7 +36,8 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
of nkIdent, nkSym:
result = n
let ident = considerQuotedIdent(c.c, n)
if c.replaceByFieldName:
if c.replaceByFieldName and
ident.id != ord(wUnderscore):
if ident.id == considerQuotedIdent(c.c, forLoop[0]).id:
let fieldName = if c.tupleType.isNil: c.field.name.s
elif c.tupleType.n.isNil: "Field" & $c.tupleIndex
@@ -45,7 +46,8 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
return
# other fields:
for i in ord(c.replaceByFieldName)..<forLoop.len-2:
if ident.id == considerQuotedIdent(c.c, forLoop[i]).id:
if ident.id == considerQuotedIdent(c.c, forLoop[i]).id and
ident.id != ord(wUnderscore):
var call = forLoop[^2]
var tupl = call[i+1-ord(c.replaceByFieldName)]
if c.field.isNil:

View File

@@ -13,3 +13,8 @@ block:
type _ = float
doAssert not (compiles do:
let x: _ = 3)
block: # bug #24339
const r = (0, 0)
for _ in r.fields:
let _ = 0