summary refs log tree commit diff stats
path: root/tests/overload/tparam_forwarding.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2018-04-29 12:50:54 +0300
committerAndreas Rumpf <rumpf_a@web.de>2018-05-07 09:37:49 +0200
commite678a4285df6e567c5e924bfae941ae6b312790d (patch)
treed1de6809152f4cdd09a018f1e31ee4583536c047 /tests/overload/tparam_forwarding.nim
parent2b8bf8fc4ae4204089a9f177c4ba62c5872d4f0a (diff)
downloadNim-e678a4285df6e567c5e924bfae941ae6b312790d.tar.gz
Bugfix: Allow matching on nkExprEqExpr against varargs[untyped]
This enables macros accepting arbitrary keyword arguments:

log("foo", prop1 = "bar", prop2 = "baz")

As an added bonus, simple templates with varargs arguments can now
forward their params to procs accepting keyword arguments.
Diffstat (limited to 'tests/overload/tparam_forwarding.nim')
-rw-r--r--tests/overload/tparam_forwarding.nim15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/overload/tparam_forwarding.nim b/tests/overload/tparam_forwarding.nim
index c1b276bfc..cd3de32e3 100644
--- a/tests/overload/tparam_forwarding.nim
+++ b/tests/overload/tparam_forwarding.nim
@@ -6,6 +6,10 @@ output: '''baz
 a
 b
 c
+x: 1, y: test 1
+x: 2, y: test 2
+x: 10, y: test 3
+x: 4, y: test 4
 '''
 """
 
@@ -35,3 +39,14 @@ templateForwarding fooVarargs, "test".len > 3, Foo(x: 10), Foo(x: 100), Foo(x: 1
 
 procForwarding "a", "b", "c"
 
+proc hasKeywordArgs(x = 10, y = "y") =
+  echo "x: ", x, ", y: ", y
+
+proc hasRegularArgs(x: int, y: string) =
+  echo "x: ", x, ", y: ", y
+
+templateForwarding(hasRegularArgs, true, 1, "test 1")
+templateForwarding(hasKeywordArgs, true, 2, "test 2")
+templateForwarding(hasKeywordArgs, true, y = "test 3")
+templateForwarding(hasKeywordArgs, true, y = "test 4", x = 4)
+