fixes #4471
This commit is contained in:
parent
bcb2365dec
commit
7a018007a4
2 changed files with 26 additions and 3 deletions
|
|
@ -48,6 +48,7 @@ type
|
||||||
etyNull, # null type
|
etyNull, # null type
|
||||||
etyProc, # proc type
|
etyProc, # proc type
|
||||||
etyBool, # bool type
|
etyBool, # bool type
|
||||||
|
etySeq, # Nim seq or string type
|
||||||
etyInt, # JavaScript's int
|
etyInt, # JavaScript's int
|
||||||
etyFloat, # JavaScript's float
|
etyFloat, # JavaScript's float
|
||||||
etyString, # JavaScript's string
|
etyString, # JavaScript's string
|
||||||
|
|
@ -156,7 +157,7 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||||
of tyBool: result = etyBool
|
of tyBool: result = etyBool
|
||||||
of tyFloat..tyFloat128: result = etyFloat
|
of tyFloat..tyFloat128: result = etyFloat
|
||||||
of tySet: result = etyObject # map a set to a table
|
of tySet: result = etyObject # map a set to a table
|
||||||
of tyString, tySequence: result = etyInt # little hack to get right semantics
|
of tyString, tySequence: result = etySeq
|
||||||
of tyObject, tyArray, tyArrayConstr, tyTuple, tyOpenArray, tyBigNum,
|
of tyObject, tyArray, tyArrayConstr, tyTuple, tyOpenArray, tyBigNum,
|
||||||
tyVarargs:
|
tyVarargs:
|
||||||
result = etyObject
|
result = etyObject
|
||||||
|
|
@ -817,7 +818,7 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
|
||||||
addf(p.body, "$#[$#] = chr($#);$n", [a.rdLoc, b.rdLoc, c.rdLoc])
|
addf(p.body, "$#[$#] = chr($#);$n", [a.rdLoc, b.rdLoc, c.rdLoc])
|
||||||
return
|
return
|
||||||
|
|
||||||
let xtyp = mapType(p, x.typ)
|
var xtyp = mapType(p, x.typ)
|
||||||
|
|
||||||
if x.kind == nkHiddenDeref and x.sons[0].kind == nkCall and xtyp != etyObject:
|
if x.kind == nkHiddenDeref and x.sons[0].kind == nkCall and xtyp != etyObject:
|
||||||
gen(p, x.sons[0], a)
|
gen(p, x.sons[0], a)
|
||||||
|
|
@ -829,7 +830,18 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
|
||||||
|
|
||||||
gen(p, y, b)
|
gen(p, y, b)
|
||||||
|
|
||||||
|
# we don't care if it's an etyBaseIndex (global) of a string, it's
|
||||||
|
# still a string that needs to be copied properly:
|
||||||
|
if x.typ.skipTypes(abstractInst).kind in {tySequence, tyString}:
|
||||||
|
xtyp = etySeq
|
||||||
case xtyp
|
case xtyp
|
||||||
|
of etySeq:
|
||||||
|
if (needsNoCopy(p, y) and needsNoCopy(p, x)) or noCopyNeeded:
|
||||||
|
addf(p.body, "$1 = $2;$n", [a.rdLoc, b.rdLoc])
|
||||||
|
else:
|
||||||
|
useMagic(p, "nimCopy")
|
||||||
|
addf(p.body, "$1 = nimCopy(null, $2, $3);$n",
|
||||||
|
[a.rdLoc, b.res, genTypeInfo(p, y.typ)])
|
||||||
of etyObject:
|
of etyObject:
|
||||||
if (needsNoCopy(p, y) and needsNoCopy(p, x)) or noCopyNeeded:
|
if (needsNoCopy(p, y) and needsNoCopy(p, x)) or noCopyNeeded:
|
||||||
addf(p.body, "$1 = $2;$n", [a.rdLoc, b.rdLoc])
|
addf(p.body, "$1 = $2;$n", [a.rdLoc, b.rdLoc])
|
||||||
|
|
@ -1430,7 +1442,7 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) =
|
||||||
discard mangleName(v, p.target)
|
discard mangleName(v, p.target)
|
||||||
gen(p, n, a)
|
gen(p, n, a)
|
||||||
case mapType(p, v.typ)
|
case mapType(p, v.typ)
|
||||||
of etyObject:
|
of etyObject, etySeq:
|
||||||
if needsNoCopy(p, n):
|
if needsNoCopy(p, n):
|
||||||
s = a.res
|
s = a.res
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
11
tests/js/tstring_assignment.nim
Normal file
11
tests/js/tstring_assignment.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
output: '''true'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #4471
|
||||||
|
when true:
|
||||||
|
let s1 = "123"
|
||||||
|
var s2 = s1
|
||||||
|
s2.setLen(0)
|
||||||
|
# fails - s1.len == 0
|
||||||
|
echo s1.len == 3
|
||||||
Loading…
Add table
Add a link
Reference in a new issue