From dc242e90277ab106cdc4d63b5ea927d4c1590521 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:40:57 +0800 Subject: [PATCH] fixes #26124; internal error: expr: param not init with nested generic procs (#26131) fixes #26124 The fix preserves the resolved static value, allowing constant folding. Co-authored-by: Andreas Rumpf --- compiler/semgnrc.nim | 8 ++++++-- tests/generics/t26124.nim | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/generics/t26124.nim diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index da9b1c187c..e8869717a3 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -129,7 +129,12 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result.typ = nil onUse(n.info, s) of skParam: - if s.owner == c.p.owner: + if s.typ != nil and s.typ.kind == tyStatic and s.typ.n != nil: + # The enclosing routine gives this static parameter a concrete value. + # Keep that value so the nested generic can fold it as a compile-time + # expression instead of generating a runtime parameter reference. + result = s.typ.n + elif s.owner == c.p.owner: # Parameters of the routine currently being semchecked stay as local # identifiers result = n @@ -681,4 +686,3 @@ proc semConceptBody(c: PContext, n: PNode): PNode = ) result = semGenericStmt(c, n, {withinConcept}, ctx) semIdeForTemplateOrGeneric(c, result, ctx.cursorInBody) - diff --git a/tests/generics/t26124.nim b/tests/generics/t26124.nim new file mode 100644 index 0000000000..5c18f6686b --- /dev/null +++ b/tests/generics/t26124.nim @@ -0,0 +1,7 @@ +proc u(k: static int) = + proc r(_: static int) = + while k > 0: + discard + r(0) + +u(0)