Skip to content

Commit

Permalink
expectLen now shows the length that we got (#13387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clyybber authored Feb 11, 2020
1 parent 8100e2e commit f6d45b4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -612,20 +612,20 @@ proc expectMinLen*(n: NimNode, min: int) {.compileTime.} =
## Checks that `n` has at least `min` children. If this is not the case,
## compilation aborts with an error message. This is useful for writing
## macros that check its number of arguments.
if n.len < min: error("macro expects a node with " & $min & " children", n)
if n.len < min: error("Expected a node with at least " & $min & " children, got " & $n.len, n)

proc expectLen*(n: NimNode, len: int) {.compileTime.} =
## Checks that `n` has exactly `len` children. If this is not the case,
## compilation aborts with an error message. This is useful for writing
## macros that check its number of arguments.
if n.len != len: error("macro expects a node with " & $len & " children", n)
if n.len != len: error("Expected a node with " & $len & " children, got " & $n.len, n)

proc expectLen*(n: NimNode, min, max: int) {.compileTime.} =
## Checks that `n` has a number of children in the range ``min..max``.
## If this is not the case, compilation aborts with an error message.
## This is useful for writing macros that check its number of arguments.
if n.len < min or n.len > max:
error("macro expects a node with " & $min & ".." & $max & " children", n)
error("Expected a node with " & $min & ".." & $max & " children, got " & $n.len, n)

proc newTree*(kind: NimNodeKind,
children: varargs[NimNode]): NimNode {.compileTime.} =
Expand Down

0 comments on commit f6d45b4

Please sign in to comment.