Do not materialize empty varargs[untyped] arrays (#8715)

When an empty nkArgList `varargs[untyped]` is passed around it is now
reused for efficiency sake and to prevent the introduction of a spurious
element: before this commit we'd pass the caller a
nkArgList[nkHiddenStdConv[nkBracket]] node instead of just an empty
nkArgList.

Fixes #8706
This commit is contained in:
LemonBoy 2018-08-31 12:16:46 +02:00 • committed by Andreas Rumpf
commit b74faf354e
2 changed files with 38 additions and 6 deletions

21
tests/macros/t8706.nim Normal file
View file

@ -0,0 +1,21 @@
discard """
output: '''0
0
'''
"""
import macros
macro varargsLen(args:varargs[untyped]): untyped =
doAssert args.kind == nnkArglist
doAssert args.len == 0
result = newLit(args.len)
template bar(a0:varargs[untyped]): untyped =
varargsLen(a0)
template foo(x: int, a0:varargs[untyped]): untyped =
bar(a0)
echo foo(42)
echo bar()