diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-04-17 23:08:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-17 17:08:53 +0200 |
commit | 91e4381a20a5b1af0f633ee8c7d0255a1530d082 (patch) | |
tree | 4edf8387380cdea3bad55ed9932ff4084c4adb3c /lib | |
parent | 8c4b7129b5b92b6cb56639c7fdf0669f7d13e542 (diff) | |
download | Nim-91e4381a20a5b1af0f633ee8c7d0255a1530d082.tar.gz |
fixes #20155; repr range with distinct types is broken in ORC (#21682)
fixes #20155; repr range with distinct types is broken with ORC
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 |