Skip to content

Commit 130eac2

Browse files
authored
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.
1 parent b8ce11d commit 130eac2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/sem.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode; producedClosure: v
346346
isArrayConstr(arg):
347347
arg.typ = eOrig.typ
348348

349+
proc resetEvalPosition(n: PNode) =
350+
# resets the eval position of variables because `tryConstExpr` may be
351+
# called multiple times on the same node
352+
case n.kind
353+
of {nkNone..nkNilLit}-{nkSym}:
354+
discard
355+
of nkSym:
356+
if n.sym.kind in {skVar, skLet} and sfGlobal notin n.sym.flags:
357+
n.sym.position = 0
358+
else:
359+
for i in 0..<n.safeLen:
360+
resetEvalPosition(n[i])
361+
349362
proc tryConstExpr(c: PContext, n: PNode; expectedType: PType = nil): PNode =
350363
var e = semExprWithType(c, n, expectedType = expectedType)
351364
if e == nil: return
@@ -382,6 +395,8 @@ proc tryConstExpr(c: PContext, n: PNode; expectedType: PType = nil): PNode =
382395
# Restore the error hook
383396
c.graph.config.structuredErrorHook = tempHook
384397

398+
resetEvalPosition(n)
399+
385400
c.config.errorCounter = oldErrorCount
386401
c.config.errorMax = oldErrorMax
387402
c.config.m.errorOutputs = oldErrorOutputs

tests/vm/tvmmisc.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,3 +813,9 @@ static:
813813
conf = defaultConf # removing this results in the expected output
814814
conf.val = 2
815815
foo2323(defaultConf)
816+
817+
818+
proc g1314(_: static bool) = discard
819+
proc g1314(_: int) = discard
820+
proc y1314() = g1314((; let k = 0; k))
821+
y1314()

0 commit comments

Comments
 (0)