You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following conditions, the bytecode does not be outputted unfortunately.
It is const declaration
It has an initializer which is not constant.
By a constant folding after analyzing AST, it has been fold to constant such as integer.
Then, the code generator will remove the code because it is a constant and it assumed to be propagated.
Cause
A constant folding is done first before analyzing AST.
After that, analyzing AST will propagate a constant to variables referencing it.
The problem is that a constant folding is done again after analyzing AST.
If the const variable becomes a constant value in the 2nd constant folding phase, the code generator will omit to generate a code even though it has not been propagated.
Code To Reproduce
In the following code, N can be removed because a variable which references it will use directly 3 as a constant. On the other hand, R will be removed but it is a problem because the number 9 has not been correctly propagated yet.
constX=10;constY=X+X;System.println(Y);
It displays nothing.
Workaround
Replace const by var, or
Write const Y = 20; directly, or
Write it like var YY = X + X; const Y = YY;, if you want Y to be const and to calculate Y by X.
The text was updated successfully, but these errors were encountered:
Problem
In the following conditions, the bytecode does not be outputted unfortunately.
Then, the code generator will remove the code because it is a constant and it assumed to be propagated.
Cause
A constant folding is done first before analyzing AST.
After that, analyzing AST will propagate a constant to variables referencing it.
The problem is that a constant folding is done again after analyzing AST.
If the const variable becomes a constant value in the 2nd constant folding phase, the code generator will omit to generate a code even though it has not been propagated.
Code To Reproduce
In the following code,
N
can be removed because a variable which references it will use directly3
as a constant. On the other hand,R
will be removed but it is a problem because the number9
has not been correctly propagated yet.It displays nothing.
Workaround
const
byvar
, orconst Y = 20;
directly, orvar YY = X + X; const Y = YY;
, if you wantY
to beconst
and to calculateY
byX
.The text was updated successfully, but these errors were encountered: