From 257965e105c219f2504a2d1d0952fc43efb9598c Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 19 Feb 2019 11:54:19 +0100 Subject: [PATCH] fixes 10697 [backport] --- compiler/jsgen.nim | 5 +++-- tests/js/tbasics.nim | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 65706cdfaf..5263230fd5 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -519,6 +519,7 @@ proc binaryUintExpr(p: PProc, n: PNode, r: var TCompRes, op: string, r.res = "$1 = (($5 $2 $3) $4)" % [a, rope op, y.rdLoc, trimmer, tmp] else: r.res = "(($1 $2 $3) $4)" % [x.rdLoc, rope op, y.rdLoc, trimmer] + r.kind = resExpr proc ternaryExpr(p: PProc, n: PNode, r: var TCompRes, magic, frmt: string) = var x, y, z: TCompRes @@ -1912,13 +1913,13 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = of mHigh: unaryExpr(p, n, r, "", "($1 != null ? ($2.length-1) : -1)") of mInc: - if n[1].typ.skipTypes(abstractRange).kind in tyUInt .. tyUInt64: + if n[1].typ.skipTypes(abstractRange).kind in {tyUInt..tyUInt64}: binaryUintExpr(p, n, r, "+", true) else: if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 += $2") else: binaryExpr(p, n, r, "addInt", "$1 = addInt($3, $2)") of ast.mDec: - if n[1].typ.skipTypes(abstractRange).kind in tyUInt .. tyUInt64: + if n[1].typ.skipTypes(abstractRange).kind in {tyUInt..tyUInt64}: binaryUintExpr(p, n, r, "-", true) else: if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 -= $2") diff --git a/tests/js/tbasics.nim b/tests/js/tbasics.nim index 0c8d33e7fd..33616776fc 100644 --- a/tests/js/tbasics.nim +++ b/tests/js/tbasics.nim @@ -2,7 +2,8 @@ discard """ output: '''ABCDC 1 14 -ok''' +ok +1''' """ type @@ -34,4 +35,14 @@ when true: a.setLen(0) - echo "ok" \ No newline at end of file + echo "ok" + +# bug #10697 +proc test2 = + var val = uint16(0) + var i = 0 + if i < 2: + val += uint16(1) + echo int(val) + +test2()