aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2015-02-13 00:59:52 +0800
committerLefteris Karapetsas <lefteris@refu.co>2015-02-14 06:16:14 +0800
commitfe725fbb49ec661fb1c5e9c3f8b58bbf6dd9e0cb (patch)
treed7c0cd34d730125286a7eeed31f01ca404605095
parentd8535eb4ea322e3d5a9f69c953fd22a1ae3f5d8d (diff)
downloaddexon-solidity-fe725fbb49ec661fb1c5e9c3f8b58bbf6dd9e0cb.tar.gz
dexon-solidity-fe725fbb49ec661fb1c5e9c3f8b58bbf6dd9e0cb.tar.zst
dexon-solidity-fe725fbb49ec661fb1c5e9c3f8b58bbf6dd9e0cb.zip
Enum type conversion and member value access.
- Added tests for the type conversion part. - Enum member value access still needs some work
-rw-r--r--SolidityEndToEndTest.cpp2
-rw-r--r--SolidityNameAndTypeResolution.cpp34
2 files changed, 35 insertions, 1 deletions
diff --git a/SolidityEndToEndTest.cpp b/SolidityEndToEndTest.cpp
index 7fa7dd25..551607df 100644
--- a/SolidityEndToEndTest.cpp
+++ b/SolidityEndToEndTest.cpp
@@ -2510,7 +2510,7 @@ BOOST_AUTO_TEST_CASE(using_enums)
}
function getChoice() returns (uint d)
{
- d = choices;
+ d = uint256(choices);
}
ActionChoices choices;
}
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index 34f51a4c..9399280b 100644
--- a/SolidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -1022,6 +1022,40 @@ BOOST_AUTO_TEST_CASE(enum_invalid_member_access)
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()
}