fixes #23139; Cannot get repr of range type of enum (#23164)

fixes #23139

(cherry picked from commit 3dee1a3e4c)
This commit is contained in:
ringabout
2024-01-05 18:07:27 +08:00
committed by narimiran
parent c3d043e980
commit 2ed16bf2d4
2 changed files with 6 additions and 1 deletions

View File

@@ -98,7 +98,7 @@ proc repr*(p: proc | iterator {.closure.}): string =
## repr of a proc as its address
repr(cast[ptr pointer](unsafeAddr p)[])
template repr*[T: distinct|range](x: T): string =
template repr*[T: distinct|(range and not enum)](x: T): string =
when T is range: # add a branch to handle range
repr(rangeBase(typeof(x))(x))
elif T is distinct:

View File

@@ -66,3 +66,8 @@ var x: array[8, CTBool[Ct[uint32]]]
x[0] = (CTBool[Ct[uint32]])(1)
echo x.repr, " ", typeof(x[0])
block: # bug #23139
type Foo = enum a, b
var x: range[a..b]
doAssert (repr x) == "a"