aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-11 22:23:50 +0800
committerchriseth <c@ethdev.com>2016-11-16 21:37:19 +0800
commit7a292c9a05eb38f10f6e619db0805105433fda30 (patch)
tree5d230d23d78b574c0783f42c41a7a76abdc88506
parent0335ed4cb476ece63224a96c8ab660116ff08c3a (diff)
downloaddexon-solidity-7a292c9a05eb38f10f6e619db0805105433fda30.tar.gz
dexon-solidity-7a292c9a05eb38f10f6e619db0805105433fda30.tar.zst
dexon-solidity-7a292c9a05eb38f10f6e619db0805105433fda30.zip
Fix parser for function type disambiguity.
-rw-r--r--libsolidity/parsing/Parser.cpp13
-rw-r--r--test/libsolidity/SolidityParser.cpp11
2 files changed, 23 insertions, 1 deletions
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index e844861b..02b7d5e0 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -315,7 +315,18 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN
m_scanner->next();
}
else if (_allowModifiers && token == Token::Identifier)
- result.modifiers.push_back(parseModifierInvocation());
+ {
+ // This can either be a modifier (function declaration) or the name of the
+ // variable (function type name plus variable).
+ if (
+ m_scanner->peekNextToken() == Token::Semicolon ||
+ m_scanner->peekNextToken() == Token::Assign
+ )
+ // Variable declaration, break here.
+ break;
+ else
+ result.modifiers.push_back(parseModifierInvocation());
+ }
else if (Token::isVisibilitySpecifier(token))
{
if (result.visibility != Declaration::Visibility::Default)
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 796da782..914dbc30 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -1338,6 +1338,17 @@ BOOST_AUTO_TEST_CASE(mapping_and_array_of_functions)
BOOST_CHECK(successParse(text));
}
+BOOST_AUTO_TEST_CASE(function_type_state_variable)
+{
+ char const* text = R"(
+ contract test {
+ function() x;
+ function() y = x;
+ }
+ )";
+ BOOST_CHECK(successParse(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()