* fix varargs forwarding for templates; fixes #5455 * document the macros' varargs change in the news for 0.16.2
This commit is contained in:
parent
d59441340d
commit
650b20dc5e
3 changed files with 42 additions and 2 deletions
37
tests/overload/tparam_forwarding.nim
Normal file
37
tests/overload/tparam_forwarding.nim
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
discard """
|
||||
output: '''baz
|
||||
10
|
||||
100
|
||||
1000
|
||||
a
|
||||
b
|
||||
c
|
||||
'''
|
||||
"""
|
||||
|
||||
type
|
||||
Foo = object
|
||||
x: int
|
||||
|
||||
proc stringVarargs*(strings: varargs[string, `$`]): void =
|
||||
for s in strings: echo s
|
||||
|
||||
proc fooVarargs*(foos: varargs[Foo]) =
|
||||
for f in foos: echo f.x
|
||||
|
||||
template templateForwarding*(callable: untyped,
|
||||
condition: bool,
|
||||
forwarded: varargs[untyped]): untyped =
|
||||
if condition:
|
||||
callable(forwarded)
|
||||
|
||||
proc procForwarding(args: varargs[string]) =
|
||||
stringVarargs(args)
|
||||
|
||||
templateForwarding stringVarargs, 17 + 4 < 21, "foo", "bar", 100
|
||||
templateForwarding stringVarargs, 10 < 21, "baz"
|
||||
|
||||
templateForwarding fooVarargs, "test".len > 3, Foo(x: 10), Foo(x: 100), Foo(x: 1000)
|
||||
|
||||
procForwarding "a", "b", "c"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue