aboutsummaryrefslogtreecommitdiffstats
path: root/SolidityNameAndTypeResolution.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-02-03 00:24:09 +0800
committerChristian <c@ethdev.com>2015-02-03 00:24:09 +0800
commita38b8890bda78559cdf43a657c987eaf2153d87a (patch)
tree1f1509e4a029aa1bfb0542de0009926c9be51266 /SolidityNameAndTypeResolution.cpp
parentbd3fed43b9710b77670bd8b3f04e90d25f311459 (diff)
downloaddexon-solidity-a38b8890bda78559cdf43a657c987eaf2153d87a.tar.gz
dexon-solidity-a38b8890bda78559cdf43a657c987eaf2153d87a.tar.zst
dexon-solidity-a38b8890bda78559cdf43a657c987eaf2153d87a.zip
Visibility specifiers.
Diffstat (limited to 'SolidityNameAndTypeResolution.cpp')
-rw-r--r--SolidityNameAndTypeResolution.cpp77
1 files changed, 73 insertions, 4 deletions
diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp
index b9a7140f..4e01d02d 100644
--- a/SolidityNameAndTypeResolution.cpp
+++ b/SolidityNameAndTypeResolution.cpp
@@ -467,6 +467,24 @@ BOOST_AUTO_TEST_CASE(illegal_override_indirect)
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
}
+BOOST_AUTO_TEST_CASE(illegal_override_visibility)
+{
+ char const* text = R"(
+ contract B { function f() protected {} }
+ contract C is B { function f() public {} }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(illegal_override_constness)
+{
+ char const* text = R"(
+ contract B { function f() constant {} }
+ contract C is B { function f() {} }
+ )";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
BOOST_AUTO_TEST_CASE(complex_inheritance)
{
char const* text = R"(
@@ -636,7 +654,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors)
" function fun() {\n"
" uint64(2);\n"
" }\n"
- "uint256 foo;\n"
+ "uint256 public foo;\n"
"}\n";
ASTPointer<SourceUnit> source;
@@ -668,16 +686,19 @@ BOOST_AUTO_TEST_CASE(private_state_variable)
" function fun() {\n"
" uint64(2);\n"
" }\n"
- "private:\n"
- "uint256 foo;\n"
+ "uint256 private foo;\n"
+ "uint256 protected bar;\n"
"}\n";
ASTPointer<SourceUnit> source;
ContractDefinition const* contract;
BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text));
BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr);
- FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()");
+ FunctionTypePointer function;
+ function = retrieveFunctionBySignature(contract, "foo()");
BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a private variable should not exist");
+ function = retrieveFunctionBySignature(contract, "bar()");
+ BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a protected variable should not exist");
}
BOOST_AUTO_TEST_CASE(fallback_function)
@@ -780,6 +801,54 @@ BOOST_AUTO_TEST_CASE(multiple_events_argument_clash)
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
}
+BOOST_AUTO_TEST_CASE(access_to_default_function_visibility)
+{
+ char const* text = R"(
+ contract c {
+ function f() {}
+ }
+ contract d {
+ function g() { c(0).f(); }
+ })";
+ BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
+}
+
+BOOST_AUTO_TEST_CASE(access_to_protected_function)
+{
+ char const* text = R"(
+ contract c {
+ function f() protected {}
+ }
+ contract d {
+ function g() { c(0).f(); }
+ })";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(access_to_default_state_variable_visibility)
+{
+ char const* text = R"(
+ contract c {
+ uint a;
+ }
+ contract d {
+ function g() { c(0).a(); }
+ })";
+ BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(access_to_protected_state_variable)
+{
+ char const* text = R"(
+ contract c {
+ uint public a;
+ }
+ contract d {
+ function g() { c(0).a(); }
+ })";
+ BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}