This commit is contained in:
Timothee Cour 2021-03-23 00:33:09 -07:00 • committed by GitHub
commit d78ebe4a0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View file

@ -1287,7 +1287,15 @@ proc `body=`*(someProc: NimNode, val: NimNode) {.compileTime.} =
else: else:
badNodeKind someProc, "body=" badNodeKind someProc, "body="
proc basename*(a: NimNode): NimNode {.compileTime, benign.} proc basename*(a: NimNode): NimNode {.raises: [].} =
## Pull an identifier from prefix/postfix expressions.
case a.kind
of nnkIdent: result = a
of nnkPostfix, nnkPrefix: result = a[1]
of nnkPragmaExpr: result = basename(a[0])
else:
error("Do not know how to get basename of (" & treeRepr(a) & ")\n" &
repr(a), a)
proc `$`*(node: NimNode): string {.compileTime.} = proc `$`*(node: NimNode): string {.compileTime.} =
## Get the string of an identifier node. ## Get the string of an identifier node.
@ -1347,16 +1355,6 @@ proc insert*(a: NimNode; pos: int; b: NimNode) {.compileTime.} =
a[i + 1] = a[i] a[i + 1] = a[i]
a[pos] = b a[pos] = b
proc basename*(a: NimNode): NimNode =
## Pull an identifier from prefix/postfix expressions.
case a.kind
of nnkIdent: result = a
of nnkPostfix, nnkPrefix: result = a[1]
of nnkPragmaExpr: result = basename(a[0])
else:
error("Do not know how to get basename of (" & treeRepr(a) & ")\n" &
repr(a), a)
proc `basename=`*(a: NimNode; val: string) {.compileTime.}= proc `basename=`*(a: NimNode; val: string) {.compileTime.}=
case a.kind case a.kind
of nnkIdent: of nnkIdent:

View file

@ -1,4 +1,4 @@
import macros import std/macros
block: # hasArgOfName block: # hasArgOfName
macro m(u: untyped): untyped = macro m(u: untyped): untyped =
@ -7,3 +7,6 @@ block: # hasArgOfName
doAssert not hasArgOfName(params u,"nonexistent") doAssert not hasArgOfName(params u,"nonexistent")
proc p(s: string; i,j,k: int; b: bool; xs,ys: seq[int] = @[]) {.m.} = discard proc p(s: string; i,j,k: int; b: bool; xs,ys: seq[int] = @[]) {.m.} = discard
block: # bug #17454
proc f(v: NimNode): string {.raises: [].} = $v