mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-21 16:31:39 +00:00
`len` could contain side effects and may result in different values when substituted twice in the template expansion. Instead, capture the result of substituting `len` once. closes: #21538
This commit is contained in:
committed by
GitHub
parent
285ea3c48e
commit
da7833c68b
@@ -1077,9 +1077,9 @@ template newSeqWith*(len: int, init: untyped): untyped =
|
||||
import std/random
|
||||
var seqRand = newSeqWith(20, rand(1.0))
|
||||
assert seqRand[0] != seqRand[1]
|
||||
|
||||
var result = newSeq[typeof(init)](len)
|
||||
for i in 0 ..< len:
|
||||
let newLen = len
|
||||
var result = newSeq[typeof(init)](newLen)
|
||||
for i in 0 ..< newLen:
|
||||
result[i] = init
|
||||
move(result) # refs bug #7295
|
||||
|
||||
|
||||
Reference in New Issue
Block a user