From 9646bfada2abc8619f39c9ed72d5671e7990b41e Mon Sep 17 00:00:00 2001 From: metagn Date: Sat, 7 Sep 2024 02:29:05 +0300 Subject: [PATCH] test template default values using other params fixes #23506 --- compiler/evaltempl.nim | 13 +++++++++++++ compiler/semexprs.nim | 2 +- compiler/semtempl.nim | 10 ++++++++++ compiler/semtypes.nim | 3 +++ tests/template/tdefaultparam.nim | 15 +++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/template/tdefaultparam.nim diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim index 5895368bb56b2..c223e11a6f610 100644 --- a/compiler/evaltempl.nim +++ b/compiler/evaltempl.nim @@ -33,6 +33,19 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) = let x = param if x.kind == nkArgList: for y in items(x): result.add(y) + elif nfDefaultRefsParam in x.flags: + # value of default param needs to be evaluated + # if it contains other template params + var res: PNode + if isAtom(x): + res = newNodeI(nkPar, x.info) + evalTemplateAux(x, actual, c, res) + if res.len == 1: res = res[0] + else: + res = copyNode(x) + for i in 0..