summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-10-27 15:37:34 +0200
committerGitHub <noreply@github.com>2016-10-27 15:37:34 +0200
commitcacbf8b32c7b910eeb6b8b5d37adf2a7dd2f343c (patch)
treefaddd5fb0ea8009db010f75c8bdff642ab5e4c2e /lib
parent38ad7400fa4ecc475b587456770e4d981dc9d037 (diff)
parent74c6500a30b99fde9af5d17a87723dcf18309964 (diff)
downloadNim-cacbf8b32c7b910eeb6b8b5d37adf2a7dd2f343c.tar.gz
Merge pull request #4963 from jangko/macro_error_improvement
Macro.error improvement fixes #4915
Diffstat (limited to 'lib')
-rw-r--r--lib/core/macros.nim8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index d584b1ac5..b0ef54397 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -235,7 +235,7 @@ proc getImpl*(s: NimSym): NimNode {.magic: "GetImpl", noSideEffect.} =
   ## const.
   discard
 
-proc error*(msg: string) {.magic: "NError", benign.}
+proc error*(msg: string, n: NimNode = nil) {.magic: "NError", benign.}
   ## writes an error message at compile time
 
 proc warning*(msg: string) {.magic: "NWarning", benign.}
@@ -377,19 +377,19 @@ proc expectKind*(n: NimNode, k: NimNodeKind) {.compileTime.} =
   ## checks that `n` is of kind `k`. If this is not the case,
   ## compilation aborts with an error message. This is useful for writing
   ## macros that check the AST that is passed to them.
-  if n.kind != k: error("Expected a node of kind " & $k & ", got " & $n.kind)
+  if n.kind != k: error("Expected a node of kind " & $k & ", got " & $n.kind, n)
 
 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")
+  if n.len < min: error("macro expects a node with " & $min & " children", 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")
+  if n.len != len: error("macro expects a node with " & $len & " children", n)
 
 proc newTree*(kind: NimNodeKind,
               children: varargs[NimNode]): NimNode {.compileTime.} =