From 8af81e3d246f5272f56a22018ef9cb67d652810a Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:51:19 +0800 Subject: [PATCH] redefining field variables is disabled --- compiler/semfields.nim | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/compiler/semfields.nim b/compiler/semfields.nim index 6e1498a140..43f159343d 100644 --- a/compiler/semfields.nim +++ b/compiler/semfields.nim @@ -17,7 +17,7 @@ type field: PSym replaceByFieldName: bool c: PContext - leftPartOfAssign: bool + leftPartOfDefinition: bool proc instFieldLoopBody(c: var TFieldInstCtx, n: PNode, forLoop: PNode): PNode = if c.field != nil and isEmptyType(c.field.typ): @@ -29,6 +29,9 @@ proc instFieldLoopBody(c: var TFieldInstCtx, n: PNode, forLoop: PNode): PNode = result = n let ident = considerQuotedIdent(c.c, n) if c.replaceByFieldName: + if c.leftPartOfDefinition: + localError(c.c.config, n.info, + "redefine field variable '$1' in a 'fields' loop" % [ident.s]) 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 @@ -38,9 +41,9 @@ proc instFieldLoopBody(c: var TFieldInstCtx, n: PNode, forLoop: PNode): PNode = # other fields: for i in ord(c.replaceByFieldName)..