Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constants with type declarations #13443

Open
HertzDevil opened this issue May 7, 2023 · 2 comments
Open

Constants with type declarations #13443

HertzDevil opened this issue May 7, 2023 · 2 comments
Labels
help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:lang

Comments

@HertzDevil
Copy link
Contributor

HertzDevil commented May 7, 2023

This is not allowed:

FOO : Int64 = 123

I think it should, because this allows constant initializers to use autocasting. In this case FOO = 0_i64 would also suffice, but things change when the integer type does not have a fixed size, e.g. it is platform-specific:

FOO : LibC::SizeT = 123

It is better than the following:

FOO = LibC::SizeT.new(123)

because it is easier for the compiler to infer in the first case that FOO is a compile-time constant and skip the generation of the run-time initializer (~FOO:init here).

Naturally this would allow Crystal::Macros::TypeDeclaration#var to be a Path node. Constant declarations with a type and without an initializer would still be disallowed, unless we further define them like in #14085 (comment).

@nobodywasishere
Copy link
Contributor

Is there anything that would prohibit this from being implemented? I think this could be really useful, and would be happy to try implementing this.

@straight-shoota
Copy link
Member

No, I don't think there are any obstacles. Just needs someone to pick it up. You're welcome to =)

@straight-shoota straight-shoota added the help wanted This issue is generally accepted and needs someone to pick it up label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:lang
Projects
None yet
Development

No branches or pull requests

3 participants