From 32780acc618b4ff2853683bc2885a20c4af8bad4 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 19 Feb 2019 11:54:19 +0100 Subject: [PATCH] fixes 10697 [backport] (cherry picked from commit 257965e105c219f2504a2d1d0952fc43efb9598c) --- compiler/jsgen.nim | 5 +++-- tests/js/tbasics.nim | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/js/tbasics.nim diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 0627d80058..f8f6febc79 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -476,6 +476,7 @@ proc binaryUintExpr(p: PProc, n: PNode, r: var TCompRes, op: string, r.res = "$1 = (($1 $2 $3) $4)" % [x.rdLoc, rope op, y.rdLoc, trimmer] 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 @@ -1706,13 +1707,13 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) = of mHigh: unaryExpr(p, n, r, "", "($1 != null ? ($1.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($1, $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 new file mode 100644 index 0000000000..33616776fc --- /dev/null +++ b/tests/js/tbasics.nim @@ -0,0 +1,48 @@ +discard """ + output: '''ABCDC +1 +14 +ok +1''' +""" + +type + MyEnum = enum + A,B,C,D +# trick the optimizer with an seq: +var x = @[A,B,C,D] +echo x[0],x[1],x[2],x[3],MyEnum(2) + +# bug #10651 + +var xa: seq[int] +var ya = @[1,2] +xa &= ya +echo xa[0] + +proc test = + var yup: seq[int] + try: + yup.add 14 + echo yup.pop + finally: + discard + +test() + +when true: + var a: seq[int] + + a.setLen(0) + + echo "ok" + +# bug #10697 +proc test2 = + var val = uint16(0) + var i = 0 + if i < 2: + val += uint16(1) + echo int(val) + +test2()