Why does the following fail to compile? The "cannot evaluate at compile time" seems wrong to my intuition about what's available here at compile time by using untyped and a template.
# example that is not compiling
template makeArray(SIZE:untyped):untyped =
var a:array[SIZE,int]
# <fancy initialization...>
a
template makeFloat(SIZE:untyped):untyped = float(SIZE*2)
proc main =
const somefloat = makeFloat(5) # okay
echo somefloat
const arr = makeArray(3) # not okay
echo arr
when isMainModule:
main()
# example that works okay
template makeArray(SIZE:untyped):untyped =
var a:array[SIZE,int]
# <fancy initialization...>
a
const arr = makeArray(3)
echo arr
This is reported on GitHub: https://github.com/nim-lang/Nim/issues/12172
Most convenient workaround afaik is const arr = (proc: auto = makeArray(3))()
Thank you!
Is there a difference between static int and static[int]? I've never seen the former.