Merge pull request #9405 from ethereum/remove-constant-keyword

[BREAKING] Removed specialized errors for constant state mutability for functions
This commit is contained in:
chriseth 2020-07-14 14:18:24 +02:00 committed by GitHub
commit 308af23615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 20 deletions

View File

@ -305,10 +305,9 @@ namespace TokenTraits
constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External; }
constexpr bool isLocationSpecifier(Token op) { return op == Token::Memory || op == Token::Storage || op == Token::CallData; }
constexpr bool isStateMutabilitySpecifier(Token op, bool _allowConstant = true)
constexpr bool isStateMutabilitySpecifier(Token op)
{
return (op == Token::Constant && _allowConstant)
|| op == Token::Pure || op == Token::View || op == Token::Payable;
return op == Token::Pure || op == Token::View || op == Token::Payable;
}
constexpr bool isEtherSubdenomination(Token op) { return op >= Token::SubWei && op <= Token::SubEther; }

View File

@ -464,14 +464,6 @@ StateMutability Parser::parseStateMutability()
case Token::Pure:
stateMutability = StateMutability::Pure;
break;
case Token::Constant:
stateMutability = StateMutability::View;
parserError(
7698_error,
"The state mutability modifier \"constant\" was removed in version 0.5.0. "
"Use \"view\" or \"pure\" instead."
);
break;
default:
solAssert(false, "Invalid state mutability specifier.");
}
@ -997,7 +989,7 @@ ASTPointer<TypeName> Parser::parseTypeName(bool _allowVar)
auto stateMutability = elemTypeName.token() == Token::Address
? optional<StateMutability>{StateMutability::NonPayable}
: nullopt;
if (TokenTraits::isStateMutabilitySpecifier(m_scanner->currentToken(), false))
if (TokenTraits::isStateMutabilitySpecifier(m_scanner->currentToken()))
{
if (elemTypeName.token() == Token::Address)
{
@ -2065,7 +2057,7 @@ Parser::LookAheadInfo Parser::peekStatementType() const
// kind of statement. This means, for example, that we do not allow type expressions of the form
// ``address payable;``.
// If we want to change this in the future, we need to consider another scanner token here.
if (TokenTraits::isElementaryTypeName(token) && TokenTraits::isStateMutabilitySpecifier(next, false))
if (TokenTraits::isElementaryTypeName(token) && TokenTraits::isStateMutabilitySpecifier(next))
return LookAheadInfo::VariableDeclaration;
if (next == Token::Identifier || TokenTraits::isLocationSpecifier(next))
return LookAheadInfo::VariableDeclaration;

View File

@ -5,4 +5,4 @@ contract C {
}
}
// ----
// ParserError 7698: (43-51): The state mutability modifier "constant" was removed in version 0.5.0. Use "view" or "pure" instead.
// ParserError 2314: (43-51): Expected '{' but got 'constant'

View File

@ -17,10 +17,7 @@ contract c6 {
function f() pure payable {}
}
contract c7 {
function f() pure constant {}
}
contract c8 {
function f() view constant {}
function f() view payable {}
}
// ----
// ParserError 9680: (39-46): State mutability already specified as "payable".
@ -29,5 +26,4 @@ contract c8 {
// ParserError 9680: (180-184): State mutability already specified as "pure".
// ParserError 9680: (229-233): State mutability already specified as "payable".
// ParserError 9680: (275-282): State mutability already specified as "pure".
// ParserError 9680: (324-332): State mutability already specified as "pure".
// ParserError 9680: (374-382): State mutability already specified as "view".
// ParserError 9680: (324-331): State mutability already specified as "view".