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:
parent
aa33bcb974
commit
b74faf354e
2 changed files with 38 additions and 6 deletions
21
tests/macros/t8706.nim
Normal file
21
tests/macros/t8706.nim
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue