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:
Lefteris Karapetsas 2015-02-12 17:59:52 +01:00
parent d8535eb4ea
commit fe725fbb49
2 changed files with 35 additions and 1 deletions

View File

@ -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;
} }

View File

@ -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()
} }