From 6f29041f0910e088e0e96f77e5aae8a39edbe5c5 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 29 Jun 2017 18:48:24 +0200 Subject: [PATCH] fixes #5563 --- compiler/jsgen.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 8a73fb8a8e..3e5cad9fd4 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1047,15 +1047,15 @@ proc genArrayAddr(p: PProc, n: PNode, r: var TCompRes) = var typ = skipTypes(m.sons[0].typ, abstractPtrs) if typ.kind == tyArray: first = firstOrd(typ.sons[0]) else: first = 0 - if optBoundsCheck in p.options and not isConstExpr(m.sons[1]): + if optBoundsCheck in p.options: useMagic(p, "chckIndx") if p.target == targetPHP: if typ.kind != tyString: - r.res = "chckIndx($1, $2, count($3))-$2" % [b.res, rope(first), a.res] + r.res = "chckIndx($1, $2, count($3)-1)-$2" % [b.res, rope(first), a.res] else: r.res = "chckIndx($1, $2, strlen($3))-$2" % [b.res, rope(first), a.res] else: - r.res = "chckIndx($1, $2, $3.length)-$2" % [b.res, rope(first), a.res] + r.res = "chckIndx($1, $2, $3.length-1)-$2" % [b.res, rope(first), a.res] elif first != 0: r.res = "($1)-$2" % [b.res, rope(first)] else: