Explicit type conversion not allowed from “int_const -1” to “uint128”

Active today

Viewed 2 times

0

I am compiling using sol 0.8.0 and the following line is producing the error in the title:

uint256 public constant MASK = uint128(~0);

Error:

Explicit type conversion not allowed from "int_const -1" to "uint128".

When changing the variable to this:

uint256 public constant MASK = ~0;

The error changes to:

Type int_const -1 is not implicitly convertible to expected type uint256. Cannot implicitly convert signed literal to unsigned type.

Please ask support questions on the solidity gitter: ethereum/solidity - Gitter

You can (and should) use uint256 public constant MASK = type(uint128).max;