mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Show previous visibility specifier in parser error
This commit is contained in:
parent
a8ca623a0f
commit
efd45f64a5
@ -1,6 +1,7 @@
|
||||
### 0.4.16 (unreleased)
|
||||
|
||||
Features:
|
||||
* Parser: Display previous visibility specifier in error if multiple are found.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user