Fix jsgen bug with uninitialized seq (#12500) [backport]

(cherry picked from commit 4ac100c912)
This commit is contained in:
Oscar Nihlgård
2019-10-24 11:17:01 +02:00
committed by narimiran
parent 6ffe5ee7e8
commit ab51a8e08b
2 changed files with 21 additions and 1 deletions

View File

@@ -1169,7 +1169,7 @@ proc genArrayAddr(p: PProc, n: PNode, r: var TCompRes) =
first = firstOrd(p.config, typ.sons[0])
if optBoundsCheck in p.options:
useMagic(p, "chckIndx")
r.res = "chckIndx($1, $2, $3.length+$2-1)-$2" % [b.res, rope(first), tmp]
r.res = "chckIndx($1, $2, ($3 != null ? $3.length : 0)+$2-1)-$2" % [b.res, rope(first), tmp]
elif first != 0:
r.res = "($1)-$2" % [b.res, rope(first)]
else:

20
tests/js/t12223.nim Normal file
View File

@@ -0,0 +1,20 @@
discard """
action: "run"
output: '''
caught
index out of bounds, the container is empty
'''
"""
proc fun() =
var z: seq[string]
discard z[4]
proc main()=
try:
fun()
except Exception as e:
echo "caught"
echo getCurrentExceptionMsg()
main()