diff options
-rw-r--r-- | lib/core/macros.nim | 8 | ||||
-rw-r--r-- | tests/stdlib/tmacros.nim | 9 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index d2985bc72..97c3a46c5 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -1434,10 +1434,10 @@ proc expectIdent*(n: NimNode, name: string) {.compileTime, since: (1,1).} = proc hasArgOfName*(params: NimNode; name: string): bool {.compileTime.}= ## Search ``nnkFormalParams`` for an argument. expectKind(params, nnkFormalParams) - for i in 1 ..< params.len: - template node: untyped = params[i] - if name.eqIdent( $ node[0]): - return true + for i in 1..<params.len: + for j in 0..<params[i].len-2: + if name.eqIdent($params[i][j]): + return true proc addIdentIfAbsent*(dest: NimNode, ident: string) {.compileTime.} = ## Add ``ident`` to ``dest`` if it is not present. This is intended for use diff --git a/tests/stdlib/tmacros.nim b/tests/stdlib/tmacros.nim new file mode 100644 index 000000000..0cc1e340c --- /dev/null +++ b/tests/stdlib/tmacros.nim @@ -0,0 +1,9 @@ +import macros + +block: # hasArgOfName + macro m(u: untyped): untyped = + for name in ["s","i","j","k","b","xs","ys"]: + doAssert hasArgOfName(params u,name) + doAssert not hasArgOfName(params u,"nonexistent") + + proc p(s: string; i,j,k: int; b: bool; xs,ys: seq[int] = @[]) {.m.} = discard |