Allow std/macros.params to work with nnkProcTy (#19563)
* Allow std/macros.params to work with nnkProcTy * Add tests for proc params & pragma
This commit is contained in:
parent
fe791c67b4
commit
ef3f343ec2
2 changed files with 33 additions and 4 deletions
|
|
@ -1271,12 +1271,19 @@ proc `name=`*(someProc: NimNode; val: NimNode) =
|
||||||
else: someProc[0] = val
|
else: someProc[0] = val
|
||||||
|
|
||||||
proc params*(someProc: NimNode): NimNode =
|
proc params*(someProc: NimNode): NimNode =
|
||||||
someProc.expectRoutine
|
if someProc.kind == nnkProcTy:
|
||||||
result = someProc[3]
|
someProc[0]
|
||||||
|
else:
|
||||||
|
someProc.expectRoutine
|
||||||
|
someProc[3]
|
||||||
|
|
||||||
proc `params=`* (someProc: NimNode; params: NimNode) =
|
proc `params=`* (someProc: NimNode; params: NimNode) =
|
||||||
someProc.expectRoutine
|
|
||||||
expectKind(params, nnkFormalParams)
|
expectKind(params, nnkFormalParams)
|
||||||
someProc[3] = params
|
if someProc.kind == nnkProcTy:
|
||||||
|
someProc[0] = params
|
||||||
|
else:
|
||||||
|
someProc.expectRoutine
|
||||||
|
someProc[3] = params
|
||||||
|
|
||||||
proc pragma*(someProc: NimNode): NimNode =
|
proc pragma*(someProc: NimNode): NimNode =
|
||||||
## Get the pragma of a proc type.
|
## Get the pragma of a proc type.
|
||||||
|
|
|
||||||
22
tests/macros/tprochelpers.nim
Normal file
22
tests/macros/tprochelpers.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import std/macros
|
||||||
|
import stdtest/testutils
|
||||||
|
|
||||||
|
macro test1(prc: untyped): untyped =
|
||||||
|
assertAll:
|
||||||
|
prc.params.len == 2
|
||||||
|
prc.params[1].len == 4
|
||||||
|
prc.pragma.len == 2
|
||||||
|
|
||||||
|
prc.params = nnkFormalParams.newTree(
|
||||||
|
ident("int")
|
||||||
|
)
|
||||||
|
prc.pragma = newEmptyNode()
|
||||||
|
|
||||||
|
assertAll:
|
||||||
|
prc.params.len == 1
|
||||||
|
prc.pragma.len == 0
|
||||||
|
prc
|
||||||
|
|
||||||
|
proc test(a, b: int): int {.gcsafe, raises: [], test1.} = 5
|
||||||
|
|
||||||
|
type hello = proc(a, b: int): int {.gcsafe, raises: [], test1.}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue