This commit is contained in:
Araq 2015-04-06 23:50:09 +02:00
commit 5bb3534f10
2 changed files with 16 additions and 2 deletions

View file

@ -1672,7 +1672,8 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
"$# = #subInt64($#, $#);$n"] "$# = #subInt64($#, $#);$n"]
const fun: array [mInc..mDec, string] = ["$# = #addInt($#, $#);$n", const fun: array [mInc..mDec, string] = ["$# = #addInt($#, $#);$n",
"$# = #subInt($#, $#);$n"] "$# = #subInt($#, $#);$n"]
if optOverflowCheck notin p.options: let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange})
if optOverflowCheck notin p.options or underlying.kind in {tyUInt..tyUInt64}:
binaryStmt(p, e, d, opr[op]) binaryStmt(p, e, d, opr[op])
else: else:
var a, b: TLoc var a, b: TLoc
@ -1681,7 +1682,6 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b) initLocExpr(p, e.sons[2], b)
let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange})
let ranged = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar}) let ranged = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar})
let res = binaryArithOverflowRaw(p, ranged, a, b, let res = binaryArithOverflowRaw(p, ranged, a, b,
if underlying.kind == tyInt64: fun64[op] else: fun[op]) if underlying.kind == tyInt64: fun64[op] else: fun[op])

View file

@ -0,0 +1,14 @@
discard """
output: '''253'''
"""
# bug #2427
import unsigned
var x = 0'u8
dec x # OverflowError
x -= 1 # OverflowError
x = x - 1 # No error
echo x