From 66e2352bf983126150d6885d3b6834ed8b85203b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 27 Feb 2025 23:48:15 +0800 Subject: [PATCH] fixes #24339; underscores used with `fields` and `fieldPairs` (#24341) fixes #24339 (cherry picked from commit 7ecb35115b4b01b15aa8316f23ba13b763cb7e50) --- compiler/semfields.nim | 6 ++++-- tests/stmt/tmiscunderscore.nim | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/semfields.nim b/compiler/semfields.nim index 7e2f5d6fdd..5bace728f3 100644 --- a/compiler/semfields.nim +++ b/compiler/semfields.nim @@ -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)..