Open mterber opened 4 years ago
Yes, the reason of the error message is because MSEC_PER_SYSTICK is nat8.
The type checker tries to infer what kind of division is needed based on the two operands (regardless of what the left hand side of the assignment may be). The type checker could promote MSEC_PER_SYSTICK to nat16 to fit the larger operand 1200 but in many other cases this could be a mistake. Only number literals are promoted in the sense that "nat16_number + 1" is okay, because (unlike a named variable) the literal "1" is not declared to be exactly of type nat8 and thus can be used everywhere it fits.
Try annotating ": nat16" to MSEC_PER_SYSTICK or use "as" to fix this issue.
Okay, got it – thanks!
Does that mean that the behavior of the Blech compiler changed with respect to this? Because my older code with the previous version of the data types has been built without any error messages.
Yes, I believe the old compiler simply checked if a common size for the operands exists. That was before we introduced type annotations.
@schorg before this issue is closed, we need to concretise the documentation of https://www.blech-lang.org/docs/user-manual/expressions/#binary-arithmetic-operations (and the following examples)
Describe the bug I recently updated an older Blech code to the newest syntax of blechc. The old code looked like this
and it compiled without any errors or warnings. Then I introduced the new data types and received the following error:![error](https://user-images.githubusercontent.com/13783234/83597727-4de11580-a568-11ea-9e94-e6438573264a.png)
For me, this error message is not plausible. I explicitly declare DCF77_SYNC_LEN as nat16. So why should the compiler try to represent it as a nat8? Is it because MSEC_PER_SYSTICK is declared as nat8? What is the difference compared to the old version of the code?
I would not expect a compilation error in this scenario.
Version info: