This small bit of code barks at compile time with (4, 35) Error: cannot evaluate at compile time: size.
type
B[S: static int] = object
template foo(size: static int): B[size] =
B[size]()
echo foo(16).repr
The error is about the size in B[size] in the template declaration. Why does the compiler complains as not knowing size value at compile time as it is declared static int?
When replacing static int by int, the error turns to Error: type mismatch: got <B[16]> but expected 'B[size]'.
The only combinations to get it compiling are if I replace size by 16, or if I remove all the static in the code. But programming is not trying syntax at random and I would like to understand why it fails when I use static.
type B[S: static[int]] = object
template foo(size: static[int]): auto = B[size]()
echo foo(16).repr
Works on my machine
I've been reading all the issues related to static and templates, macros and typedesc. I see that I'm entering the fuzzy zone where Nim typing is not totally defined and the syntax is moving. The discussions on generics vs type variables shows that there's no consensus on how types variability must be managed in Nim. And I think that it impacts finding a clean way to solve these types of bugs.
Meanwhile, I have to find a way to change my code to stay in Nim safer areas, if possible.