diff --git a/lib/system.nim b/lib/system.nim index a79f26b4c7..2b34b94925 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2963,12 +2963,16 @@ when notJSnotNims and not defined(nimSeqsV2): assert y == "abcgh" discard -proc arrayWith*[T](y: T, size: static int): array[size, T] {.raises: [].} = +proc arrayWith*[T](y: T, size: static int): array[size, T] {.noinit, nodestroy, raises: [].} = ## Creates a new array filled with `y`. for i in 0..size-1: - result[i] = y + when (NimMajor, NimMinor, NimPatch) >= (2, 3, 1): + result[i] = `=dup`(y) + else: + wasMoved(result[i]) + `=copy`(result[i], y) -proc arrayWithDefault*[T](size: static int): array[size, T] {.raises: [].} = +proc arrayWithDefault*[T](size: static int): array[size, T] {.noinit, nodestroy, raises: [].} = ## Creates a new array filled with `default(T)`. for i in 0..size-1: result[i] = default(T) diff --git a/lib/system/seqs_v2.nim b/lib/system/seqs_v2.nim index 572e77408f..6ace66afea 100644 --- a/lib/system/seqs_v2.nim +++ b/lib/system/seqs_v2.nim @@ -144,8 +144,11 @@ proc grow*[T](x: var seq[T]; newLen: Natural; value: T) {.nodestroy.} = xu.p = cast[typeof(xu.p)](prepareSeqAddUninit(oldLen, xu.p, newLen - oldLen, sizeof(T), alignof(T))) xu.len = newLen for i in oldLen .. newLen-1: - wasMoved(xu.p.data[i]) - `=copy`(xu.p.data[i], value) + when (NimMajor, NimMinor, NimPatch) >= (2, 3, 1): + xu.p.data[i] = `=dup`(value) + else: + wasMoved(xu.p.data[i]) + `=copy`(xu.p.data[i], value) proc add*[T](x: var seq[T]; y: sink T) {.magic: "AppendSeqElem", noSideEffect, nodestroy.} = ## Generic proc for adding a data item `y` to a container `x`.