fixes system.add for strict funcs (#15259)
* fixes system.add for strict funcs * fixes #15248
This commit is contained in:
parent
3172ca5475
commit
48f2997221
2 changed files with 21 additions and 19 deletions
|
|
@ -342,7 +342,7 @@ proc deps(c: var Partitions; dest, src: PNode) =
|
|||
let destIsComplex = types.searchTypeFor(dest.typ, wrap)
|
||||
|
||||
for t in targets:
|
||||
if dest.kind != nkSym:
|
||||
if dest.kind != nkSym and c.inNoSideEffectSection == 0:
|
||||
potentialMutation(c, t, dest.info)
|
||||
|
||||
if destIsComplex:
|
||||
|
|
|
|||
|
|
@ -1227,9 +1227,10 @@ proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} =
|
|||
## .. code-block:: Nim
|
||||
## var s: seq[string] = @["test2","test2"]
|
||||
## s.add("test") # s <- @[test2, test2, test]
|
||||
let xl = x.len
|
||||
setLen(x, xl + y.len)
|
||||
for i in 0..high(y): x[xl+i] = y[i]
|
||||
{.noSideEffect.}:
|
||||
let xl = x.len
|
||||
setLen(x, xl + y.len)
|
||||
for i in 0..high(y): x[xl+i] = y[i]
|
||||
|
||||
when defined(nimSeqsV2):
|
||||
template movingCopy(a, b) =
|
||||
|
|
@ -1283,22 +1284,23 @@ proc insert*[T](x: var seq[T], item: sink T, i = 0.Natural) {.noSideEffect.} =
|
|||
## .. code-block:: Nim
|
||||
## var i = @[1, 3, 5]
|
||||
## i.insert(99, 0) # i <- @[99, 1, 3, 5]
|
||||
template defaultImpl =
|
||||
let xl = x.len
|
||||
setLen(x, xl+1)
|
||||
var j = xl-1
|
||||
while j >= i:
|
||||
movingCopy(x[j+1], x[j])
|
||||
dec(j)
|
||||
when nimvm:
|
||||
defaultImpl()
|
||||
else:
|
||||
when defined(js):
|
||||
var it : T
|
||||
{.emit: "`x` = `x` || []; `x`.splice(`i`, 0, `it`);".}
|
||||
else:
|
||||
{.noSideEffect.}:
|
||||
template defaultImpl =
|
||||
let xl = x.len
|
||||
setLen(x, xl+1)
|
||||
var j = xl-1
|
||||
while j >= i:
|
||||
movingCopy(x[j+1], x[j])
|
||||
dec(j)
|
||||
when nimvm:
|
||||
defaultImpl()
|
||||
x[i] = item
|
||||
else:
|
||||
when defined(js):
|
||||
var it : T
|
||||
{.emit: "`x` = `x` || []; `x`.splice(`i`, 0, `it`);".}
|
||||
else:
|
||||
defaultImpl()
|
||||
x[i] = item
|
||||
|
||||
when not defined(nimV2):
|
||||
proc repr*[T](x: T): string {.magic: "Repr", noSideEffect.}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue