summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2018-12-30 00:40:21 -0800
committerAndreas Rumpf <rumpf_a@web.de>2018-12-30 09:40:21 +0100
commita6633b965891a7f5e70ac6fcf41d4142145b69c2 (patch)
tree3fc98ab67d9b4b0760f8396bc8a33d46e91b288b
parentaadbdd6b066bc7251c6d24bb5ef5ce3f940825ec (diff)
downloadNim-a6633b965891a7f5e70ac6fcf41d4142145b69c2.tar.gz
fix typetraits.`$` regression https://github.com/c-blake/cligen/issues/84 (#10131)
* fix typetraits.`$` regression https://github.com/c-blake/cligen/issues/84
* add test
-rw-r--r--compiler/semmagic.nim5
-rw-r--r--lib/pure/typetraits.nim2
-rw-r--r--tests/metatype/ttypetraits2.nim3
3 files changed, 8 insertions, 2 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index 568b418e9..05c8b181c 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -129,7 +129,8 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
   template typeWithSonsResult(kind, sons): PNode =
     newTypeWithSons(context, kind, sons).toNode(traitCall.info)
 
-  case trait.sym.name.s
+  let s = trait.sym.name.s
+  case s
   of "or", "|":
     return typeWithSonsResult(tyOr, @[operand, operand2])
   of "and":
@@ -160,7 +161,7 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
                      hasDestructor(t)
     result = newIntNodeT(ord(not complexObj), traitCall, c.graph)
   else:
-    localError(c.config, traitCall.info, "unknown trait")
+    localError(c.config, traitCall.info, "unknown trait: " & s)
     result = newNodeI(nkEmpty, traitCall.info)
 
 proc semTypeTraits(c: PContext, n: PNode): PNode =
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim
index db57ac02d..5f5bfdbd7 100644
--- a/lib/pure/typetraits.nim
+++ b/lib/pure/typetraits.nim
@@ -10,6 +10,8 @@
 ## This module defines compile-time reflection procs for
 ## working with types
 
+export system.`$`
+
 proc name*(t: typedesc): string {.magic: "TypeTrait".}
   ## Alias for system.`$`(t) since Nim v0.20.0.
 
diff --git a/tests/metatype/ttypetraits2.nim b/tests/metatype/ttypetraits2.nim
new file mode 100644
index 000000000..de80e10b1
--- /dev/null
+++ b/tests/metatype/ttypetraits2.nim
@@ -0,0 +1,3 @@
+# todo: merge with $nimc_D/tests/metatype/ttypetraits.nim (currently disabled)
+
+from typetraits import `$` # checks fix for https://github.com/c-blake/cligen/issues/84