From a6633b965891a7f5e70ac6fcf41d4142145b69c2 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sun, 30 Dec 2018 00:40:21 -0800 Subject: [PATCH] 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 --- compiler/semmagic.nim | 5 +++-- lib/pure/typetraits.nim | 2 ++ tests/metatype/ttypetraits2.nim | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/metatype/ttypetraits2.nim 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