Constant Evaluation Enhancement #2220
frightster
started this conversation in
Ideas/Requests
Replies: 1 comment
-
I have improved this error message now printing the value and explaining why it cannot be casted:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem? Please describe.
Consider the following situation:
The result of
CHORUS_BUFFER_SIZE
amounts to 88,371.99, or just shy of 88,372. However, Odin will not accept this value, because it expects to have an integer, not a float. Unfortunately, Odin does not explain this very well, and instead provides the following error messages:It's difficult to decipher exactly what the problem is from this. Consider this other situation:
This will succeed, because the result of multiplying CONST_A by CONST_B is 4.0, which translates directly into an integer, which Odin will accept happily. This is confounding unless you're aware that Odin is simply not accepting floats which cannot be directly correlated to integers, as Odin will not round the result to the nearest integer, as it otherwise might when casting at runtime.
Describe the solution you'd like
Ideally, Odin will be expanded with better constant evaluation support, where it can round a float into the nearest integer; more ideally, Odin will be able to run procedures at compile time to produce constants, such as through a constant
math.floor
or constantmath.ceil
, which would allow better control over how a const float becomes a const integer.At least, Odin should provide a clearer error message as to why one const fails to compile, while another const doing something very similar succeeds. However, this still begets workarounds due to the lack of ability to round a float to the nearest integer.
Beta Was this translation helpful? Give feedback.
All reactions