I found that the newSeqWith may fail when init is constant Slice like 0..10 . I also found that if init is typed, it can be compiled. Should it be untyped?
template newSeqWith*(len: int, init: untyped): untyped =
var result = newSeq[typeof(init)](len)
for i in 0 ..< len:
result[i] = init
move(result) # refs bug #7295
var a = newSeqWith(10, 0 .. 10)
echo a
typeof has default TypeOfMode typeOfIter which evaluates as int for 0 .. 10 since 0 .. 10 is also an integer iterator as well as a slice constructor. Use typeOfProc. typeof docs
template newSeqWith*(len: int, init: untyped): untyped =
var result = newSeq[typeof(init, typeOfProc)](len)
for i in 0 ..< len:
result[i] = init
move(result) # refs bug #7295
var a = newSeqWith(10, 0 .. 10)
echo a
Thank you very much!
Then, should the original newSeqWith proc be fixed?