fix range to unsigned conversion (#17754)
This commit is contained in:
parent
5c9c1988f6
commit
8e124da75d
2 changed files with 13 additions and 1 deletions
|
|
@ -409,7 +409,7 @@ proc handleRange(f, a: PType, min, max: TTypeKind): TTypeRelation =
|
||||||
elif a.kind == tyRange and
|
elif a.kind == tyRange and
|
||||||
# Make sure the conversion happens between types w/ same signedness
|
# Make sure the conversion happens between types w/ same signedness
|
||||||
(f.kind in {tyInt..tyInt64} and a[0].kind in {tyInt..tyInt64} or
|
(f.kind in {tyInt..tyInt64} and a[0].kind in {tyInt..tyInt64} or
|
||||||
f.kind in {tyUInt8..tyUInt32} and a[0].kind in {tyUInt8..tyInt32}) and
|
f.kind in {tyUInt8..tyUInt32} and a[0].kind in {tyUInt8..tyUInt32}) and
|
||||||
a.n[0].intVal >= firstOrd(nil, f) and a.n[1].intVal <= lastOrd(nil, f):
|
a.n[0].intVal >= firstOrd(nil, f) and a.n[1].intVal <= lastOrd(nil, f):
|
||||||
# passing 'nil' to firstOrd/lastOrd here as type checking rules should
|
# passing 'nil' to firstOrd/lastOrd here as type checking rules should
|
||||||
# not depend on the target integer size configurations!
|
# not depend on the target integer size configurations!
|
||||||
|
|
|
||||||
|
|
@ -142,3 +142,15 @@ var a: array[4'u, string]
|
||||||
|
|
||||||
for i in 0..<a.len:
|
for i in 0..<a.len:
|
||||||
a[i] = "foo"
|
a[i] = "foo"
|
||||||
|
|
||||||
|
# Check range to ordinal conversions
|
||||||
|
block:
|
||||||
|
var
|
||||||
|
a: int16
|
||||||
|
b: range[0'i32..45'i32] = 3
|
||||||
|
c: uint16
|
||||||
|
d: range[0'u32..46'u32] = 3
|
||||||
|
a = b
|
||||||
|
c = d
|
||||||
|
doAssert a == b
|
||||||
|
doAssert c == d
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue