diff options
author | zah <zahary@gmail.com> | 2017-03-13 23:02:11 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-03-13 22:02:11 +0100 |
commit | 650b20dc5e9a1ce7e0990e2edc0ed01e6f0cada4 (patch) | |
tree | a57391c0e881827f04f846230802d44fc785dc78 /tests/overload | |
parent | d59441340dcc3b131c984def530084da93796775 (diff) | |
download | Nim-650b20dc5e9a1ce7e0990e2edc0ed01e6f0cada4.tar.gz |
fix varargs forwarding for templates; fixes #5455 (#5505)
* fix varargs forwarding for templates; fixes #5455 * document the macros' varargs change in the news for 0.16.2
Diffstat (limited to 'tests/overload')
-rw-r--r-- | tests/overload/tparam_forwarding.nim | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/overload/tparam_forwarding.nim b/tests/overload/tparam_forwarding.nim new file mode 100644 index 000000000..c1b276bfc --- /dev/null +++ b/tests/overload/tparam_forwarding.nim @@ -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" + |