From 1514706def81dbfe10986bd85bac95780cc51f8b Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 10:06:48 +0100 Subject: [PATCH] consts work --- compiler/ast2nif.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index fc7fa80820..aa67d5e8c9 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -406,8 +406,9 @@ proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) = writeType(w, dest, sym.typImpl) writeSym(w, dest, sym.ownerFieldImpl) - # Store the AST for routine symbols (procs, funcs, etc.) - if sym.kindImpl in routineKinds: + # Store the AST for routine symbols and constants + # Constants need their AST for astdef() to return the constant's value + if sym.kindImpl in routineKinds + {skConst}: writeNode(w, dest, sym.astImpl, forAst = true) else: dest.addDotToken @@ -1110,8 +1111,9 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule: # the simple loadTypeStub here. s.typImpl = loadTypeStub(c, n, localSyms) s.ownerFieldImpl = loadSymStub(c, n, thisModule, localSyms) - # Load the AST for routine symbols (procs, funcs, etc.) - if s.kindImpl in routineKinds: + # Load the AST for routine symbols and constants + # Constants need their AST for astdef() to return the constant's value + if s.kindImpl in routineKinds + {skConst}: s.astImpl = loadNode(c, n, thisModule, localSyms) elif n.kind == DotToken: inc n