This commit is contained in:
Araq 2018-02-10 21:20:48 +01:00
commit 2c1f1f21bf
3 changed files with 21 additions and 3 deletions

View file

@ -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))