I would like to specify the size of an array inside a object at compiletime with generics, like:
type
Matrix0[x:int] = object
v: array[x, float64]
w: int # width of matrix
h: int
var a: Matrix0[6]
but the compiler says
fatal.nim(49) sysFatal
Error: unhandled exception: int128.nim(72, 11) `arg.sdata(2) == 0` out of range [AssertionError]
exit status 1
What am I doing wrong? Is it a compiler-bug? Is there a workaround?
You need to do it like this:
type
Matrix0[x: static int] = object
v: array[x, float64]
h: int
var a: Matrix0[6]
echo a.x