umka-lang icon indicating copy to clipboard operation
umka-lang copied to clipboard

"Map literals are not allowed for constants" outside of constants.

Open ske2004 opened this issue 9 months ago • 1 comments

When defining a global variable:

numpadPaths := map[[2]char]str{}
keypadPaths := map[[2]char]str{}

For some reason it's treated as a constant.

ske2004 avatar Feb 28 '25 12:02 ske2004

In Umka, no code can be executed outside functions, except for the initial jump to the main entry point. Therefore, you can use only constant expressions to initialize global variables. Since your expressions are trivially zeros, you can just write

var numpadPaths, keypadPaths: map[[2]char]str

However, it would be nice to support constant expressions for maps, as I do it for dynamic arrays.

vtereshkov avatar Feb 28 '25 12:02 vtereshkov