summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-07-03 10:55:50 +0200
committerAraq <rumpf_a@web.de>2015-07-03 10:55:50 +0200
commit60ac5e3e76fe24e015782a081da3f04f0000ea5f (patch)
tree7768d0b553b647874cc177ecb3847eb21f96e513
parent2d196442fa6db010307a2dc62c65f1129ce9705d (diff)
downloadNim-60ac5e3e76fe24e015782a081da3f04f0000ea5f.tar.gz
fixes #3046
-rw-r--r--lib/core/macros.nim6
-rw-r--r--tests/macros/tbugs.nim18
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index 21eebfa6a..044020b2a 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -164,7 +164,7 @@ proc kind*(n: NimNode): NimNodeKind {.magic: "NKind", noSideEffect.}
   ## returns the `kind` of the node `n`.
 
 proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.}
-proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} = n.intVal != 0
+
 proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.}
 proc symbol*(n: NimNode): NimSym {.magic: "NSymbol", noSideEffect.}
 proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect.}
@@ -833,6 +833,10 @@ proc addIdentIfAbsent*(dest: NimNode, ident: string) {.compiletime.} =
     else: discard
   dest.add(ident(ident))
 
+proc boolVal*(n: NimNode): bool {.compileTime, noSideEffect.} =
+  if n.kind == nnkIntLit: n.intVal != 0
+  else: n == bindSym"true" # hacky solution for now
+
 when not defined(booting):
   template emit*(e: static[string]): stmt =
     ## accepts a single string argument and treats it as nim code
diff --git a/tests/macros/tbugs.nim b/tests/macros/tbugs.nim
index 1ecb0d4cc..1bfce6bc4 100644
--- a/tests/macros/tbugs.nim
+++ b/tests/macros/tbugs.nim
@@ -9,7 +9,10 @@ TTaa
 TTaa
 true
 true
-nil'''
+nil
+42
+false
+true'''
 
 output: '''test
 2'''
@@ -88,3 +91,16 @@ proc calc(): array[1, int] =
 
 const c = calc()
 echo c[0]
+
+
+# bug #3046
+
+macro sampleMacroInt(i: int): stmt =
+  echo i.intVal
+
+macro sampleMacroBool(b: bool): stmt =
+  echo b.boolVal
+
+sampleMacroInt(42)
+sampleMacroBool(false)
+sampleMacroBool(system.true)