Is there a solution for the following? I've been wresting with this for a few days, and really expected this use of const to work.
const ArrayOfStrings = compileTimeGeneratedArray()
macroTakesAStaticString( ArrayOfStrings[2] ) # works okay!
for astring in ArrayOfStrings:
macroTakesAStaticString(astring) # fails because no longer known to the compiler?
static:
for astring in ArrayOfStrings:
macroTakesAStaticString(astring) # also fails
static:
const ArrayLength = len(ArrayOfStrings)
for i in 0 ..< ArrayLength:
macroTakesAStaticString( ArrayOfStrings[i] ) # also fails
It's also not obvious to me that ForLoopStmt would help at all - seems to simply move the problem.
static macro parameter means that it is either a literal, or constant expression that can be evaluated explicitly. When you use ArrayOfStrings[2] you get second case - all necessary info to evaluate argument is in here. When you add a loop (regardless of any combination of const and static: blocks you use), this information is no longer available.
Putting things to static does not unroll the loop automatically, same with using const parameters.