Solidity Type Conversion – Explicit Type Conversion Not Allowed from ‘int_const -1’ to ‘uint128’

soliditysolidity-0.8.x

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.

Best Answer

Changed it to this:

uint256 public constant MASK = type(uint128).max;

New restrictions in 0.8.0

Related Topic