JS backend properly extends string with setLen (#21087)
* Add test case * Extend string with '0' when setting length to be longer
This commit is contained in:
parent
1fefb8e92a
commit
7ae7832f76
2 changed files with 14 additions and 1 deletions
|
|
@ -2209,7 +2209,9 @@ proc genMagic(p: PProc, n: PNode, r: var TCompRes) =
|
|||
if optOverflowCheck notin p.options: binaryExpr(p, n, r, "", "$1 -= $2")
|
||||
else: binaryExpr(p, n, r, "subInt", "$1 = subInt($3, $2)", true)
|
||||
of mSetLengthStr:
|
||||
binaryExpr(p, n, r, "mnewString", "($1.length = $2)")
|
||||
binaryExpr(p, n, r, "mnewString",
|
||||
"""if ($1.length < $2) { for (var i = $3.length; i < $4; ++i) $3.push(0); }
|
||||
else {$3.length = $4; }""")
|
||||
of mSetLengthSeq:
|
||||
var x, y: TCompRes
|
||||
gen(p, n[1], x)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue