fixes #3144
This commit is contained in:
parent
94ad731964
commit
beca7ded1b
3 changed files with 57 additions and 20 deletions
28
tests/metatype/tstatic_ones.nim
Normal file
28
tests/metatype/tstatic_ones.nim
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
discard """
|
||||
output: "@[2, 2, 2, 2, 2]"
|
||||
"""
|
||||
|
||||
# bug #3144
|
||||
|
||||
type IntArray[N: static[int]] = array[N, int]
|
||||
|
||||
proc `$`(a: IntArray): string = $(@(a))
|
||||
|
||||
proc `+=`[N: static[int]](a: var IntArray[N], b: IntArray[N]) =
|
||||
for i in 0 .. < N:
|
||||
a[i] += b[i]
|
||||
|
||||
proc zeros(N: static[int]): IntArray[N] =
|
||||
for i in 0 .. < N:
|
||||
result[i] = 0
|
||||
|
||||
proc ones(N: static[int]): IntArray[N] =
|
||||
for i in 0 .. < N:
|
||||
result[i] = 1
|
||||
|
||||
proc sum[N: static[int]](vs: seq[IntArray[N]]): IntArray[N] =
|
||||
result = zeros(N)
|
||||
for v in vs:
|
||||
result += v
|
||||
|
||||
echo sum(@[ones(5), ones(5)])
|
||||
Loading…
Add table
Add a link
Reference in a new issue