make range type checking more restrictive, see tn8vsint16 test case; minor breaking change
This commit is contained in:
parent
6f9cd35733
commit
286f895280
2 changed files with 28 additions and 1 deletions
|
|
@ -390,7 +390,16 @@ proc isConvertibleToRange(f, a: PType): bool =
|
||||||
# be less picky for tyRange, as that it is used for array indexing:
|
# be less picky for tyRange, as that it is used for array indexing:
|
||||||
if f.kind in {tyInt..tyInt64, tyUInt..tyUInt64} and
|
if f.kind in {tyInt..tyInt64, tyUInt..tyUInt64} and
|
||||||
a.kind in {tyInt..tyInt64, tyUInt..tyUInt64}:
|
a.kind in {tyInt..tyInt64, tyUInt..tyUInt64}:
|
||||||
result = true
|
case f.kind
|
||||||
|
of tyInt, tyInt64: result = true
|
||||||
|
of tyInt8: result = a.kind in {tyInt8, tyInt}
|
||||||
|
of tyInt16: result = a.kind in {tyInt8, tyInt16, tyInt}
|
||||||
|
of tyInt32: result = a.kind in {tyInt8, tyInt16, tyInt32, tyInt}
|
||||||
|
of tyUInt, tyUInt64: result = true
|
||||||
|
of tyUInt8: result = a.kind in {tyUInt8, tyUInt}
|
||||||
|
of tyUInt16: result = a.kind in {tyUInt8, tyUInt16, tyUInt}
|
||||||
|
of tyUInt32: result = a.kind in {tyUInt8, tyUInt16, tyUInt32, tyUInt}
|
||||||
|
else: result = false
|
||||||
elif f.kind in {tyFloat..tyFloat128} and
|
elif f.kind in {tyFloat..tyFloat128} and
|
||||||
a.kind in {tyFloat..tyFloat128}:
|
a.kind in {tyFloat..tyFloat128}:
|
||||||
result = true
|
result = true
|
||||||
|
|
|
||||||
18
tests/range/tn8vsint16.nim
Normal file
18
tests/range/tn8vsint16.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
output: '''9'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
n32 = range[0..high(int)]
|
||||||
|
n8* = range[0'i8..high(int8)]
|
||||||
|
|
||||||
|
proc `+`*(a: n32, b: n32{nkIntLit}): n32 = discard
|
||||||
|
|
||||||
|
proc `-`*(a: n8, b: n8): n8 = n8(system.`-`(a, b))
|
||||||
|
|
||||||
|
var x, y: n8
|
||||||
|
var z: int16
|
||||||
|
|
||||||
|
# ensure this doesn't call our '-' but system.`-` for int16:
|
||||||
|
echo z - n8(9)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue