diff --git a/compiler/sem.nim b/compiler/sem.nim index 0739c6e162c7..38da68a0b05c 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..