From a4982bd74de050a46a3154d32be617dc60a2407f Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 22 Jan 2026 16:50:25 +0800 Subject: [PATCH] fixes #25446; [FieldDefect] with static: discard cast[pointer](default(pointer)) (#25448) fixes #25446 supports this since `static: discard cast[pointer](nil)` works (cherry picked from commit 39864980d1ee60f1c33a26fe5b5104eb16e0d475) --- compiler/vm.nim | 5 ++++- tests/vm/tvmmisc.nim | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index 8b462c4d99..57132f1ad5 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -663,7 +663,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of rkNode: if regs[rb].node.typ.kind notin PtrLikeKinds: stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].node.typ: " & $regs[rb].node.typ.kind) - node2.intVal = regs[rb].node.intVal + if regs[rb].node.kind == nkNilLit: + node2.intVal = 0 + else: + node2.intVal = regs[rb].node.intVal else: stackTrace(c, tos, pc, "opcCastIntToPtr: regs[rb].kind: " & $regs[rb].kind) regs[ra].node = node2 of opcAsgnComplex: diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim index 610dd26691..e2d979fad6 100644 --- a/tests/vm/tvmmisc.nim +++ b/tests/vm/tvmmisc.nim @@ -814,6 +814,8 @@ static: conf.val = 2 foo2323(defaultConf) + discard cast[pointer](default(pointer)) # bug #25446 + proc g1314(_: static bool) = discard proc g1314(_: int) = discard