aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-27 22:32:48 +0800
committerGitHub <noreply@github.com>2017-06-27 22:32:48 +0800
commit708d17d13fce9095178962c2ebc3fa17303b72f3 (patch)
tree774625d27d8f372e10132760248b349016247f94
parent36044c8c95890bfc25a199510e32a0481e8082d0 (diff)
parent70fd5c17704119a3f52aba5c67eda96c2a222d2d (diff)
downloaddexon-solidity-708d17d13fce9095178962c2ebc3fa17303b72f3.tar.gz
dexon-solidity-708d17d13fce9095178962c2ebc3fa17303b72f3.tar.zst
dexon-solidity-708d17d13fce9095178962c2ebc3fa17303b72f3.zip
Merge pull request #2464 from federicobond/deprecate-function-type-names
Warn deprecated usage of parameter names in function types
-rw-r--r--docs/types.rst4
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp12
-rw-r--r--libsolidity/analysis/SyntaxChecker.h2
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp20
4 files changed, 36 insertions, 2 deletions
diff --git a/docs/types.rst b/docs/types.rst
index 0a0bffea..dfab79c8 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -387,10 +387,10 @@ Example that shows how to use internal function types::
}
function reduce(
uint[] memory self,
- function (uint x, uint y) returns (uint) f
+ function (uint, uint) returns (uint) f
)
internal
- returns (uint r)
+ returns (uint)
{
r = self[0];
for (uint i = 1; i < self.length; i++) {
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index 35d71d85..02e2fdcf 100644
--- a/libsolidity/analysis/SyntaxChecker.cpp
+++ b/libsolidity/analysis/SyntaxChecker.cpp
@@ -148,3 +148,15 @@ bool SyntaxChecker::visit(PlaceholderStatement const&)
return true;
}
+bool SyntaxChecker::visit(FunctionTypeName const& _node)
+{
+ for (auto const& decl: _node.parameterTypeList()->parameters())
+ if (!decl->name().empty())
+ m_errorReporter.warning(decl->location(), "Naming function type parameters is deprecated.");
+
+ for (auto const& decl: _node.returnParameterTypeList()->parameters())
+ if (!decl->name().empty())
+ m_errorReporter.warning(decl->location(), "Naming function type return parameters is deprecated.");
+
+ return true;
+}
diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h
index b1857aa5..ec6ac434 100644
--- a/libsolidity/analysis/SyntaxChecker.h
+++ b/libsolidity/analysis/SyntaxChecker.h
@@ -63,6 +63,8 @@ private:
virtual bool visit(PlaceholderStatement const& _placeholderStatement) override;
+ virtual bool visit(FunctionTypeName const& _node) override;
+
ErrorReporter& m_errorReporter;
/// Flag that indicates whether a function modifier actually contains '_'.
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index b489be22..c8a04539 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -5129,6 +5129,26 @@ BOOST_AUTO_TEST_CASE(external_function_type_to_uint)
CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed");
}
+BOOST_AUTO_TEST_CASE(warn_function_type_parameters_with_names)
+{
+ char const* text = R"(
+ contract C {
+ function(uint a) f;
+ }
+ )";
+ CHECK_WARNING(text, "Naming function type parameters is deprecated.");
+}
+
+BOOST_AUTO_TEST_CASE(warn_function_type_return_parameters_with_names)
+{
+ char const* text = R"(
+ contract C {
+ function(uint) returns(bool ret) f;
+ }
+ )";
+ CHECK_WARNING(text, "Naming function type return parameters is deprecated.");
+}
+
BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue)
{
char const* text = R"(