mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Enum type conversion and member value access.
- Added tests for the type conversion part. - Enum member value access still needs some work
This commit is contained in:
parent
d8535eb4ea
commit
fe725fbb49
@ -2510,7 +2510,7 @@ BOOST_AUTO_TEST_CASE(using_enums)
|
|||||||
}
|
}
|
||||||
function getChoice() returns (uint d)
|
function getChoice() returns (uint d)
|
||||||
{
|
{
|
||||||
d = choices;
|
d = uint256(choices);
|
||||||
}
|
}
|
||||||
ActionChoices choices;
|
ActionChoices choices;
|
||||||
}
|
}
|
||||||
|
@ -1022,6 +1022,40 @@ BOOST_AUTO_TEST_CASE(enum_invalid_member_access)
|
|||||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
enum ActionChoices { GoLeft, GoRight, GoStraight, Sit };
|
||||||
|
function test()
|
||||||
|
{
|
||||||
|
a = uint256(ActionChoices.GoStraight);
|
||||||
|
b = uint64(ActionChoices.Sit);
|
||||||
|
}
|
||||||
|
uint256 a;
|
||||||
|
uint64 b;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK_NO_THROW(parseTextAndResolveNamesWithChecks(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
enum ActionChoices { GoLeft, GoRight, GoStraight, Sit };
|
||||||
|
function test()
|
||||||
|
{
|
||||||
|
a = ActionChoices.GoStraight;
|
||||||
|
b = ActionChoices.Sit;
|
||||||
|
}
|
||||||
|
uint256 a;
|
||||||
|
uint64 b;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user