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.
This commit is contained in:
parent
2b8bf8fc4a
commit
e678a4285d
2 changed files with 17 additions and 1 deletions
|
|
@ -2173,7 +2173,8 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||||
var formal: PSym = if formalLen > 1: m.callee.n.sons[1].sym else: nil
|
var formal: PSym = if formalLen > 1: m.callee.n.sons[1].sym else: nil
|
||||||
|
|
||||||
while a < n.len:
|
while a < n.len:
|
||||||
if a >= formalLen-1 and formal != nil and formal.typ.isVarargsUntyped:
|
if a >= formalLen-1 and f < formalLen and m.callee.n[f].typ.isVarargsUntyped:
|
||||||
|
formal = m.callee.n.sons[f].sym
|
||||||
incl(marker, formal.position)
|
incl(marker, formal.position)
|
||||||
if container.isNil:
|
if container.isNil:
|
||||||
container = newNodeIT(nkArgList, n.sons[a].info, arrayConstr(c, n.info))
|
container = newNodeIT(nkArgList, n.sons[a].info, arrayConstr(c, n.info))
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@ output: '''baz
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
c
|
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"
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue