I have tried defining types parametric in a static[int], and do arithmetic on this numbers. Turns out, this does not work.
What is an issue, though, is that the compiler does not report an error, nor does it manage to compile, but silently crashes. This happen when compiling, for instance
type
Foo[a: static[int]] = array[a, int]
Bar[a, b: static[int]] = array[b, Foo[a/2]]
echo "done"
When running nim c example.nim I do not get any error, but no executable is produced as well.
(Just to help people searching the forums)
internalError(n.info, "cannot generate code for: " & s.name.s)
to
globalError(n.info, "cannot generate code for: " & s.name.s)
and then recompiling the compiler, I could then compile the test code at --verbosity:2 and got the message:
c.nim(5, 40) Error: cannot instantiate Foo
got: (float)
but expected: (a)
Bar[a, b: static[int]] = array[b, Foo[a/2]]
I don't know nearly enough about the internals to suggest a fix, but the compiler "crash" seems to be a problem with the error reporting, and not with the codegen. [edit: this doesn't address the typing issue, of course, just the apparent compiler crash.]
You are right that / is the wrong operation. Still, even when using, say +, the code does not compile.
As of today, though, the error reporting seems correct.
When I reported the issue, changing the inline operation to a proc would make everything work. As of today, this seems not to work anymore