// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract ErrorDataType {
? ?
? ? // Function: hoistingDemo
? ? // This function is designed to demonstrate handling of data type limits in Solidity.
? ? function hoistingDemo() public pure returns (uint){
? ? ? ? // Declare a uint8 variable, 'someVar'.
? ? ? ? // The uint8 data type can store values from 0 to 255.
? ? ? ? uint8 someVar = 100;
? ? ? ? // Add a check to ensure the new value after addition is within the range of uint8
? ? ? ? if (uint256(someVar) + 300 <= 255) {
? ? ? ? ? ? // If the addition stays within the range, update 'someVar'
? ? ? ? ? ? someVar = uint8(uint256(someVar) + 300);
? ? ? ? } else {
? ? ? ? ? ? // If the addition exceeds the range, handle appropriately,
? ? ? ? ? ? // e.g., set 'someVar' to its maximum value
? ? ? ? ? ? someVar = 255;
? ? ? ? }
? ? ? ? // Return the value of 'someVar', converted to uint (uint256)
? ? ? ? return someVar;
? ? }
? ?
}
//Deploy screenshot: