mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-07 04:14:19 +00:00
fixes #2427
This commit is contained in:
@@ -1672,7 +1672,8 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||
"$# = #subInt64($#, $#);$n"]
|
||||
const fun: array [mInc..mDec, string] = ["$# = #addInt($#, $#);$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])
|
||||
else:
|
||||
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[2], b)
|
||||
|
||||
let underlying = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar, tyRange})
|
||||
let ranged = skipTypes(e.sons[1].typ, {tyGenericInst, tyVar})
|
||||
let res = binaryArithOverflowRaw(p, ranged, a, b,
|
||||
if underlying.kind == tyInt64: fun64[op] else: fun[op])
|
||||
|
||||
14
tests/misc/tunsignedinc.nim
Normal file
14
tests/misc/tunsignedinc.nim
Normal 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
|
||||
Reference in New Issue
Block a user