fixes #15052
This commit is contained in:
parent
5c4e2bf68e
commit
624762cfb7
2 changed files with 22 additions and 0 deletions
|
|
@ -729,6 +729,15 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc) =
|
||||||
else:
|
else:
|
||||||
putIntoDest(p, d, e, "(*$1)" % [rdLoc(a)], a.storage)
|
putIntoDest(p, d, e, "(*$1)" % [rdLoc(a)], a.storage)
|
||||||
|
|
||||||
|
proc cow(p: BProc; n: PNode) =
|
||||||
|
if n.kind == nkHiddenAddr and optSeqDestructors in p.config.globalOptions:
|
||||||
|
if n[0].kind == nkBracketExpr:
|
||||||
|
let strCandidate = n[0][0]
|
||||||
|
if strCandidate.typ.skipTypes(abstractInst).kind == tyString:
|
||||||
|
var a: TLoc
|
||||||
|
initLocExpr(p, strCandidate, a)
|
||||||
|
linefmt(p, cpsStmts, "#nimPrepareStrMutationV2($1);$n", [byRefLoc(p, a)])
|
||||||
|
|
||||||
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# careful 'addr(myptrToArray)' needs to get the ampersand:
|
# careful 'addr(myptrToArray)' needs to get the ampersand:
|
||||||
if e[0].typ.skipTypes(abstractInstOwned).kind in {tyRef, tyPtr}:
|
if e[0].typ.skipTypes(abstractInstOwned).kind in {tyRef, tyPtr}:
|
||||||
|
|
@ -2699,9 +2708,11 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
of nkReturnStmt: genReturnStmt(p, n)
|
of nkReturnStmt: genReturnStmt(p, n)
|
||||||
of nkBreakStmt: genBreakStmt(p, n)
|
of nkBreakStmt: genBreakStmt(p, n)
|
||||||
of nkAsgn:
|
of nkAsgn:
|
||||||
|
cow(p, n[1])
|
||||||
if nfPreventCg notin n.flags:
|
if nfPreventCg notin n.flags:
|
||||||
genAsgn(p, n, fastAsgn=false)
|
genAsgn(p, n, fastAsgn=false)
|
||||||
of nkFastAsgn:
|
of nkFastAsgn:
|
||||||
|
cow(p, n[1])
|
||||||
if nfPreventCg notin n.flags:
|
if nfPreventCg notin n.flags:
|
||||||
# transf is overly aggressive with 'nkFastAsgn', so we work around here.
|
# transf is overly aggressive with 'nkFastAsgn', so we work around here.
|
||||||
# See tests/run/tcnstseq3 for an example that would fail otherwise.
|
# See tests/run/tcnstseq3 for an example that would fail otherwise.
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ whiley ends :(
|
||||||
new line before - @['a']
|
new line before - @['a']
|
||||||
new line after - @['a']
|
new line after - @['a']
|
||||||
finalizer
|
finalizer
|
||||||
|
aaaaa
|
||||||
closed
|
closed
|
||||||
destroying variable: 20
|
destroying variable: 20
|
||||||
destroying variable: 10
|
destroying variable: 10
|
||||||
|
|
@ -282,3 +283,13 @@ proc hello(): int =
|
||||||
|
|
||||||
var leaves {.global.} = hello()
|
var leaves {.global.} = hello()
|
||||||
doAssert leaves == 42
|
doAssert leaves == 42
|
||||||
|
|
||||||
|
# bug #15052
|
||||||
|
|
||||||
|
proc mutstrings =
|
||||||
|
var data = "hello"
|
||||||
|
for c in data.mitems():
|
||||||
|
c = 'a'
|
||||||
|
echo data
|
||||||
|
|
||||||
|
mutstrings()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue