diff options
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 30 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.h | 1 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 4 |
4 files changed, 32 insertions, 4 deletions
diff --git a/Changelog.md b/Changelog.md index a61ac0af..0381d434 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.4.16 (unreleased) Features: + * Parser: Display previous visibility specifier in error if multiple are found. Bugfixes: diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index d1f9c1fa..7e1d36dd 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -307,6 +307,24 @@ Declaration::Visibility Parser::parseVisibilitySpecifier(Token::Value _token) return visibility; } +string Parser::visibilitySpecifierName(Declaration::Visibility _visibility) +{ + switch(_visibility) + { + case Declaration::Visibility::Public: + return "public"; + case Declaration::Visibility::Internal: + return "internal"; + case Declaration::Visibility::Private: + return "private"; + case Declaration::Visibility::External: + return "external"; + default: + solAssert(false, "Invalid visibility specifier."); + } + return string(); +} + Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers) { FunctionHeaderParserResult result; @@ -354,7 +372,11 @@ Parser::FunctionHeaderParserResult Parser::parseFunctionHeader(bool _forceEmptyN { if (result.visibility != Declaration::Visibility::Default) { - parserError(string("Visibility already specified.")); + parserError(string( + "Visibility already specified as \"" + + visibilitySpecifierName(result.visibility) + + "\"." + )); m_scanner->next(); } else @@ -512,7 +534,11 @@ ASTPointer<VariableDeclaration> Parser::parseVariableDeclaration( { if (visibility != Declaration::Visibility::Default) { - parserError(string("Visibility already specified.")); + parserError(string( + "Visibility already specified as \"" + + visibilitySpecifierName(visibility) + + "\"." + )); m_scanner->next(); } else diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 19631c58..82ab91a6 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -73,6 +73,7 @@ private: ASTPointer<ContractDefinition> parseContractDefinition(Token::Value _expectedKind); ASTPointer<InheritanceSpecifier> parseInheritanceSpecifier(); Declaration::Visibility parseVisibilitySpecifier(Token::Value _token); + std::string visibilitySpecifierName(Declaration::Visibility _visibility); FunctionHeaderParserResult parseFunctionHeader(bool _forceEmptyName, bool _allowModifiers); ASTPointer<ASTNode> parseFunctionDefinitionOrFunctionTypeStateVariable(ASTString const* _contractName); ASTPointer<FunctionDefinition> parseFunctionDefinition(ASTString const* _contractName); diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index d7ada518..2be824d6 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -898,12 +898,12 @@ BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) contract c { uint private internal a; })"; - CHECK_PARSE_ERROR(text, "Visibility already specified."); + CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\"."); text = R"( contract c { function f() private external {} })"; - CHECK_PARSE_ERROR(text, "Visibility already specified."); + CHECK_PARSE_ERROR(text, "Visibility already specified as \"private\"."); } BOOST_AUTO_TEST_CASE(multiple_payable_specifiers) |