From efd45f64a542c722d750f79b483dd7428aba16ed Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 9 Aug 2017 13:35:38 +0100 Subject: Show previous visibility specifier in parser error --- libsolidity/parsing/Parser.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'libsolidity/parsing/Parser.cpp') 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 Parser::parseVariableDeclaration( { if (visibility != Declaration::Visibility::Default) { - parserError(string("Visibility already specified.")); + parserError(string( + "Visibility already specified as \"" + + visibilitySpecifierName(visibility) + + "\"." + )); m_scanner->next(); } else -- cgit