fixes #3985
This commit is contained in:
parent
b57d14b1ae
commit
2c1f1f21bf
3 changed files with 21 additions and 3 deletions
|
|
@ -375,7 +375,12 @@ proc getAppType(n: PNode): PNode =
|
|||
result = newStrNodeT("console", n)
|
||||
|
||||
proc rangeCheck(n: PNode, value: BiggestInt) =
|
||||
if value < firstOrd(n.typ) or value > lastOrd(n.typ):
|
||||
var err = false
|
||||
if n.typ.skipTypes({tyRange}).kind in {tyUInt..tyUInt64}:
|
||||
err = value <% firstOrd(n.typ) or value >% lastOrd(n.typ, fixedUnsigned=true)
|
||||
else:
|
||||
err = value < firstOrd(n.typ) or value > lastOrd(n.typ)
|
||||
if err:
|
||||
localError(n.info, errGenerated, "cannot convert " & $value &
|
||||
" to " & typeToString(n.typ))
|
||||
|
||||
|
|
|
|||
|
|
@ -621,7 +621,7 @@ proc firstOrd*(t: PType): BiggestInt =
|
|||
internalError("invalid kind for first(" & $t.kind & ')')
|
||||
result = 0
|
||||
|
||||
proc lastOrd*(t: PType): BiggestInt =
|
||||
proc lastOrd*(t: PType; fixedUnsigned = false): BiggestInt =
|
||||
case t.kind
|
||||
of tyBool: result = 1
|
||||
of tyChar: result = 255
|
||||
|
|
@ -640,11 +640,14 @@ proc lastOrd*(t: PType): BiggestInt =
|
|||
of tyInt64: result = 0x7FFFFFFFFFFFFFFF'i64
|
||||
of tyUInt:
|
||||
if platform.intSize == 4: result = 0xFFFFFFFF
|
||||
elif fixedUnsigned: result = 0xFFFFFFFFFFFFFFFF'i64
|
||||
else: result = 0x7FFFFFFFFFFFFFFF'i64
|
||||
of tyUInt8: result = 0xFF
|
||||
of tyUInt16: result = 0xFFFF
|
||||
of tyUInt32: result = 0xFFFFFFFF
|
||||
of tyUInt64: result = 0x7FFFFFFFFFFFFFFF'i64
|
||||
of tyUInt64:
|
||||
if fixedUnsigned: result = 0xFFFFFFFFFFFFFFFF'i64
|
||||
else: result = 0x7FFFFFFFFFFFFFFF'i64
|
||||
of tyEnum:
|
||||
assert(t.n.sons[sonsLen(t.n) - 1].kind == nkSym)
|
||||
result = t.n.sons[sonsLen(t.n) - 1].sym.position
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ true
|
|||
1
|
||||
0
|
||||
it should stop now
|
||||
18446744073709551615
|
||||
4294967295
|
||||
'''
|
||||
"""
|
||||
|
||||
|
|
@ -31,3 +33,11 @@ for i in countdown(count, 0):
|
|||
if i == 0:
|
||||
echo "it should stop now"
|
||||
stop_me = true
|
||||
|
||||
# bug #3985
|
||||
const
|
||||
HIGHEST_64BIT_UINT = 0xFFFFFFFFFFFFFFFF'u
|
||||
HIGHEST_32BIT_UINT = 0xFFFFFFFF'u
|
||||
|
||||
echo($HIGHEST_64BIT_UINT)
|
||||
echo($HIGHEST_32BIT_UINT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue