diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/system/repr_v2.nim | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/system/repr_v2.nim b/lib/system/repr_v2.nim index f6c720e2c..206b5c5f5 100644 --- a/lib/system/repr_v2.nim +++ b/lib/system/repr_v2.nim @@ -9,6 +9,9 @@ proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} proc distinctBase(T: typedesc, recursive: static bool = true): typedesc {.magic: "TypeTrait".} ## imported from typetraits +proc rangeBase(T: typedesc): typedesc {.magic: "TypeTrait".} + # skip one level of range; return the base type of a range type + proc repr*(x: NimNode): string {.magic: "Repr", noSideEffect.} proc repr*(x: int): string = @@ -95,8 +98,13 @@ proc repr*(p: proc): string = ## repr of a proc as its address repr(cast[ptr pointer](unsafeAddr p)[]) -template repr*(x: distinct): string = - repr(distinctBase(typeof(x))(x)) +template repr*[T: distinct|range](x: T): string = + when T is range: # add a branch to handle range + repr(rangeBase(typeof(x))(x)) + elif T is distinct: + repr(distinctBase(typeof(x))(x)) + else: + {.error: "cannot happen".} template repr*(t: typedesc): string = $t |