From 9c07bb94c1eb170f3b358043cff40d12d7fcd5ae Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 1 Apr 2026 06:24:06 +0800 Subject: [PATCH] fixes #25682; fix vm genAsgn to handle statementListExpr (#25686) fixes #25682 This pull request introduces a fix to the Nim compiler's assignment code generation logic to better handle statement list expressions, and adds regression tests to ensure correct behavior when assigning to object fields via templates. The changes address a specific bug (#25682) related to assignments using templates with side effects in static contexts. **Compiler code generation improvements:** * Updated the `genAsgn` procedure in `compiler/vmgen.nim` to properly handle assignments where the left-hand side is a `nkStmtListExpr` (statement list expression), ensuring all statements except the last are executed before the assignment occurs. **Regression tests for assignment semantics:** * Added new test blocks in `tests/vm/tvmmisc.nim` to verify that template-based assignments to object fields work as expected in static contexts, specifically testing for bug #25682. --- compiler/vmgen.nim | 3 +++ tests/vm/tvmmisc.nim | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index ad009298ca..898b5b5def 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1726,6 +1726,9 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) = of nkHiddenStdConv, nkHiddenSubConv, nkConv: if sameBackendType(le.typ, le[1].typ): genAsgn(c, le[1], ri, requiresCopy) + of nkStmtListExpr: + for i in 0..