-
Notifications
You must be signed in to change notification settings - Fork 55
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
Wrong downcast warning #828
Comments
Lines 897 to 911 in 47bb28f
i think we can replace everything in the first else with |
Default behavior on all arithmetic operations is to do them with DINT (same as C does with the int type) The warning you get is technically correct, the addition and multiplication will always default to DINT. Not sure yet how we solve this, @99NIMI's idea is certainly a possibility if there is no reason for the conversion. Another is we need to mark this type of conversions (where all types are the same) as legal.. |
We don't really need to do this, but we followed C's integral promotion strategy. The idea is basically, that anyway every arithmetic operation will be performed on at least 32bit numbers on the CPU level, so we need to cast them anyway. Btw. Java does exactly the same! Furthermore it is incredibly hard to guess the correct type-size for a literal. Since the LLVM IR offers arithmetic operations for all sizes, we would just need to ensure that both operands have the same type. This means that annotating literal integers are a bit harder :-/. If we keep them at DINT we will have the same problem.
We already do some type-updates of "right hand side" expressions but it gets hard if you have complex stuff like:
For the last example you start annotating this tree from the bottom up:
this example gives you probably the wrong result, without any validation problems (you didnt want the mySINT + 100 to overflow when you ulitmately assign it to a DINT. Is it possible to backpropagate the DINT down the tree once you realized the end-result? - is it easy? idk This whole feature reminds me more of rust's checked_add, checked_sub, etc. functions. |
The following code
will report
which is wrong because
a
,b
andc
are of type INTThe text was updated successfully, but these errors were encountered: