-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Error when array length is an expression involving only literals and type conversions: Invalid array length, expected integer literal or constant expression
#12832
Comments
I think the issue is that the constant is too large - we should improve the error message. |
also errors similarly. But here there is something else wrong. |
On debugging, it looks like the constant evaluator does not evaluate explicitly typed constant literals like |
Minor update: This error is also encountered when statically defined array size is a compile-time constant but is not in a form that will be evaluated as such because it is not of a |
I believe this should be dealt with in |
The constant is definitely too large. We don't really support exponentiation in arbitrary precision with such large numbers. If you remove explicit conversions, you get this error message:
And you don't even need numbers that large to get this error. You'd get it even with something like
I think it's by design. It seems to be the same kind of issue as #12677. I.e. expressions stop being treated as compile-time constants once you convert to a limited-precision type. It's not ideal but at least does not look like a bug to me. I think we should just properly document what is considered a "constant expression" or a "compile-time constant" and maybe also adjust the error message to be clearer about that. |
Invalid array length, expected integer literal or constant expression
Invalid array length, expected integer literal or constant expression
Invalid array length, expected integer literal or constant expression
I believe this can be closed by #12885 |
Two things we might still want to do as a part of this:
What do you think? |
I think that'll be a a good temporary workaround before we fully address the second thing.
I do think we should make the constant evaluator more aggressive by stripping away type conversion for applicable constants. With the limited context I have, that seems to address the issue at its root. Also similar things are suggested in another thread. I'd gladly try sending a PR for this, if we think it's worth attempting and viable. |
We can't just strip the conversion. It may affect the value (e.g. casting I think issue I think we should just update docs/messages and close it, leaving evaluation for #3157. |
You are right, I'll look into #3157.
Agree! |
It's a rather big task. Compile-time evaluation is something we've been discussing for a while now. It's on our roadmap but we're not even decided on all details yet. Are you interested in getting that specific feature implemented in the compiler or are you just looking for a good task to contribute in general? If it's the latter, I can find you a better defined task. If the former, you should really come to one of our team calls and join the design discussion on that topic (note that the next few calls might be a bit sparsely attended due to Devconnect though). |
Thanks for the info! I'd say for now I'm just looking for a small tasks to contribute in general. If you can give me some pointers, I'll try to pick them up when possible:). |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
throws the said error although the length literal is an integer literal and a constant expression.
The text was updated successfully, but these errors were encountered: