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
The compiler exhibits an inconsistent treatment of constant expressions evaluation.
When applying bitwise negation on uint256 max value (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF), the compiler reports error for some expressions, but does not report an error in others.
When the expression appears as part of division, an error is reported.
contract BitwiseSolver {
uint256 constant largeConstant = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
function test() public returns (uint256) {
return 1/(~largeConstant);
}
}
However, when the expression stands on its own, no error is reported.
contract BitwiseSolver {
uint256 constant largeConstant = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
function test() public returns (uint256) {
return ~largeConstant;
}
}
Note that if the definition is inlined and the bitwise negation is applied directly to a literal a conversion error is reported:
contract BitwiseSolver {
function test() public returns (uint256) {
return ~0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
}
}
Error: Return argument type int_const -115...(71 digits omitted)...9936 is not implicitly convertible to expected type (type of first return variable) uint256. Cannot implicitly convert signed literal to unsigned type.
--> test2.sol:3:16:
|
3 | return ~0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The text was updated successfully, but these errors were encountered:
Description
The compiler exhibits an inconsistent treatment of constant expressions evaluation.
When applying bitwise negation on uint256 max value (
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
), the compiler reports error for some expressions, but does not report an error in others.When the expression appears as part of division, an error is reported.
Error reported:
However, when the expression stands on its own, no error is reported.
Note that if the definition is inlined and the bitwise negation is applied directly to a literal a conversion error is reported:
The text was updated successfully, but these errors were encountered: