Fixes #16219, hasArgOfName ignoring argument sets. (#16233)

* Fixes #16219, `hasArgOfName` ignoring argument sets.

* Fix test and simplify ident traversal.

* Moved test into a block and removed some boilerplate.

* Fix some argument formatting.

* use ..<

* Change the preceding line too

Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
Aditya Siram 2020-12-03 06:40:28 -06:00 • committed by GitHub
commit 23447ffdce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -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