mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 19:34:12 +00:00
@@ -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")
|
||||
|
||||
48
tests/js/tbasics.nim
Normal file
48
tests/js/tbasics.nim
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user