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)