activity Main ()()
await true
var x: nat32 = 142000
var y: nat16 = (x / 10) as! nat16
end
leads to the following C implementation
blc_pc_t blc_01test01_Main (struct blc_01test01_Main *blc_00_ctx) {
if ( blc_00_ctx->pc_1 == 2 ) {
blc_00_ctx->pc_1 = 5; /* proceed from surface to depth */
}
if ( blc_00_ctx->pc_1 == 4 ) {
if ( 1 ) {
blc_00_ctx->blc_Main_x = 142000;
blc_00_ctx->blc_Main_y = (blc_nat16)blc_00_ctx->blc_Main_x / 10;
blc_00_ctx->pc_1 = 0; /* end */
}
}
BLC_SWITCH_TO_NEXTSTEP(blc_00_ctx->pc_1);
return blc_00_ctx->pc_1 ;
}
Line blc_00_ctx->blc_Main_y = (blc_nat16)blc_00_ctx->blc_Main_x / 10; shows that the parentheses of the original blech code var y: nat16 = (x / 10) as! nat16 are missing. Since the type cast has a higher precedence than the division operator this leads to a wrong computation result - the type cast is done before the division by 10.
Describe the bug The following blech code
leads to the following C implementation
Line
blc_00_ctx->blc_Main_y = (blc_nat16)blc_00_ctx->blc_Main_x / 10;
shows that the parentheses of the original blech codevar y: nat16 = (x / 10) as! nat16
are missing. Since the type cast has a higher precedence than the division operator this leads to a wrong computation result - the type cast is done before the division by 10.Expected behaviour The expected behavior is
Additional context Blech toolchain in use: