aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-09-06 16:58:56 +0800
committerchriseth <c@ethdev.com>2016-09-06 16:58:56 +0800
commit384f189a6adffa7b1879bb06ded4453ef5f00dcb (patch)
treed3a57bda669a8f693d86342af8dcdfd8c6dddd28
parentff11aa192708620de538ed8676136eb616abc74e (diff)
downloaddexon-solidity-384f189a6adffa7b1879bb06ded4453ef5f00dcb.tar.gz
dexon-solidity-384f189a6adffa7b1879bb06ded4453ef5f00dcb.tar.zst
dexon-solidity-384f189a6adffa7b1879bb06ded4453ef5f00dcb.zip
Tests for payable / private combination.
-rw-r--r--libsolidity/analysis/TypeChecker.cpp4
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp20
2 files changed, 22 insertions, 2 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index eea4619d..06e26a76 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -423,9 +423,9 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
typeError(_function.location(), "Library functions cannot be payable.");
if (!_function.isConstructor() && !_function.name().empty() && !_function.isPartOfExternalInterface())
typeError(_function.location(), "Internal functions cannot be payable.");
+ if (_function.isDeclaredConst())
+ typeError(_function.location(), "Functions cannot be constant and payable at the same time.");
}
- if (_function.isPayable() && _function.isDeclaredConst())
- typeError(_function.location(), "Functions cannot be constant and payable at the same time.");
for (ASTPointer<VariableDeclaration> const& var: _function.parameters() + _function.returnParameters())
{
if (!type(*var)->canLiveOutsideStorage())
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 29c0ccba..ab0f9c7b 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3865,6 +3865,16 @@ BOOST_AUTO_TEST_CASE(payable_in_library)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(payable_external)
+{
+ char const* text = R"(
+ contract test {
+ function f() payable external {}
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(payable_internal)
{
char const* text = R"(
@@ -3875,6 +3885,16 @@ BOOST_AUTO_TEST_CASE(payable_internal)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(payable_private)
+{
+ char const* text = R"(
+ contract test {
+ function f() payable private {}
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
BOOST_AUTO_TEST_CASE(illegal_override_payable)
{
char const* text = R"(