See title. I've tried:
type
A = enum
a, b, c
Subrange = range[b..c]
#echo A.b in Subrange # doesn't compile
echo A.b in Subrange.low..Subrange.high # looks fine, except...
echo A.a in Subrange.low..Subrange.high # RangeDefect at runtime :(
echo A.a in Subrange.low.A..Subrange.high.A # finally works, but...really?
Am I missing something?
type
A = enum
X, Y, Z
B = Y..Z
doAssert Y isnot B
const Range = B.low..B.high
doAssert Y in Range
let b = B(Y)
doAssert b is B
doAssert b in Range
doAssert b is A
type SR = range[B.low..B.high]
doAssert Y isnot SR
let yr = SR.low
doAssert yr is SR
doAssert yr is B
# ...but requires conversion for direct comparison
doAssert yr.B == B.low
in check for ranges, is checks for types.
I think he's more interested in knowing why is the behavior different from the expected 0 notin 1..2
type
A = enum
a, b, c
Subrange = range[b..c]
assert 0 notin 1..2
try:
echo "A.a in Subrange.low..Subrange.high = " & $(A.a in Subrange.low..Subrange.high)
except RangeDefect:
echo "raises RangeDefect"
This outputs,
A.a in Subrange.low..Subrange.high = false
raises RangeDefect
My question is why it throws after evaluating correctly.