solidity/test/libsolidity/semanticTests/enums/enum_explicit_overflow_homestead.sol
hrkrshnn 03f58c6b52 Strict explicit conversion between literals and enums
Explicit conversions between literals and enums are only allowed if the literal can represent a
value in the enum.
2020-11-06 19:15:02 +01:00

33 lines
843 B
Solidity

contract test {
enum ActionChoices {GoLeft, GoRight, GoStraight}
constructor() {}
function getChoiceExp(uint256 x) public returns (uint256 d) {
choice = ActionChoices(x);
d = uint256(choice);
}
function getChoiceFromSigned(int256 x) public returns (uint256 d) {
choice = ActionChoices(x);
d = uint256(choice);
}
function getChoiceFromMax() public returns (uint256 d) {
choice = ActionChoices(type(uint256).max);
d = uint256(choice);
}
ActionChoices choice;
}
// ====
// EVMVersion: <byzantium
// compileViaYul: also
// ----
// getChoiceExp(uint256): 3 -> FAILURE # These should throw #
// getChoiceFromSigned(int256): -1 -> FAILURE
// getChoiceFromMax() -> FAILURE
// getChoiceExp(uint256): 2 -> 2 # These should work #
// getChoiceExp(uint256): 0 -> 0