gleam
gleam copied to clipboard
Cannot make a const list of other constants
Trying to write a constant list of other constants results in an error, please see https://johndoneth.github.io/gleam-playground/?s=MYewdgzgLgBAhjAvDARHFAoUlYCMmq6bbQzAErDHily7nIDacANDLm8ALpA%3D for an example.
error: Syntax error
┌─ src/main.gleam:4:14
│
4 │ const abc = [a, b, c]
│ ^ This type is not allowed in module constants.
See: https://gleam.run/book/tour/constants
@lpil mentioned in Discord earlier that this limitation is unintended, and should be fixed.
The issue at least starts in the parser, in the parse_const_value
function: https://github.com/gleam-lang/gleam/blob/a0d3cf1a0fa2a4bf821360470b8da7d1a18a55cc/compiler-core/src/parse.rs#L1931-L2027
The TL;DR is that this functions expects constant values to be literals. The only use of Token::Name
(i.e. a lowercase string token) that's allowed is when it is being used to refer to a remote type constructor, like uri
in uri.URI(scheme: ...)
.
Updating the match arm for Token::Name
would be a start, but there may be further updates may need to be made in the code generation layers.
I'll have a go at fixing this tomorrow.
Update: I realize now that this will mean introducing a new Constant::Var
AST node, which implies that it may be a lot of work :sweat_smile:
Yes, let's fix this one. Happy to answer any questions RE implementation.
This issue doesn't seem to be present in the current version. (0.30.3)
Thank you