From 3bbba9e0ffb33012dd7c0ceb022014ad63bfdb4e Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 28 Oct 2025 18:47:20 +0800 Subject: [PATCH] fixes #25008; Compiler internal error with static overload (#25234) fixes #25008 It seems that `semOverloadedCall` evaluates the same node twice using `tryConstExpr` in order for `efExplain` to print all the diagnostic output. The problem is that `tryConstExpr` has side effects, i.e., it changes the slot index of variables after VM execution. (cherry picked from commit 130eac2f9358964d07e49e604d0d6db36f7a46f8) --- compiler/sem.nim | 15 +++++++++++++++ tests/vm/tvmmisc.nim | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/compiler/sem.nim b/compiler/sem.nim index 0739c6e162..38da68a0b0 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -346,6 +346,19 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode; producedClosure: v isArrayConstr(arg): arg.typ = eOrig.typ +proc resetEvalPosition(n: PNode) = + # resets the eval position of variables because `tryConstExpr` may be + # called multiple times on the same node + case n.kind + of {nkNone..nkNilLit}-{nkSym}: + discard + of nkSym: + if n.sym.kind in {skVar, skLet} and sfGlobal notin n.sym.flags: + n.sym.position = 0 + else: + for i in 0..