aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp3
-rw-r--r--libsolidity/ast/Types.cpp4
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp36
3 files changed, 41 insertions, 2 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index 41cad922..c49af013 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -95,7 +95,8 @@ void ReferencesResolver::endVisit(FunctionTypeName const& _typeName)
typeError(_typeName.location(), "Invalid visibility, can only be \"external\" or \"internal\".");
}
- // Do we allow storage references for external functions?
+ if (_typeName.isPayable() && _typeName.visibility() != VariableDeclaration::Visibility::External)
+ fatalTypeError(_typeName.location(), "Only external function types can be payable.");
_typeName.annotation().type = make_shared<FunctionType>(_typeName);
}
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 395faf55..e18735d9 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -1704,7 +1704,7 @@ TypePointer TupleType::closestTemporaryType(TypePointer const& _targetType) cons
FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal):
m_location(_isInternal ? Location::Internal : Location::External),
m_isConstant(_function.isDeclaredConst()),
- m_isPayable(_function.isPayable()),
+ m_isPayable(_isInternal ? false : _function.isPayable()),
m_declaration(&_function)
{
TypePointers params;
@@ -1810,6 +1810,8 @@ FunctionType::FunctionType(FunctionTypeName const& _typeName):
m_isConstant(_typeName.isDeclaredConst()),
m_isPayable(_typeName.isPayable())
{
+ if (_typeName.isPayable())
+ solAssert(m_location == Location::External, "Internal payable function type used.");
for (auto const& t: _typeName.parameterTypes())
{
solAssert(t->annotation().type, "Type not set for parameter.");
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 62fb55f7..5916ed10 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -4192,6 +4192,42 @@ BOOST_AUTO_TEST_CASE(public_function_type)
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
+BOOST_AUTO_TEST_CASE(payable_internal_function_type)
+{
+ char const* text = R"(
+ contract C {
+ function (uint) internal payable returns (uint) x;
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(call_value_on_non_payable_function_type)
+{
+ char const* text = R"(
+ contract C {
+ function (uint) external returns (uint) x;
+ function f() {
+ x.value(2)();
+ }
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(call_value_on_payable_function_type)
+{
+ char const* text = R"(
+ contract C {
+ function (uint) external payable returns (uint) x;
+ function f() {
+ x.value(2)(1);
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter)
{
// It should not be possible to give internal functions