mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Constants at file-level.
This commit is contained in:
@@ -276,11 +276,17 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
|
||||
if (_variable.annotation().type)
|
||||
return;
|
||||
|
||||
if (_variable.isConstant() && !_variable.isStateVariable())
|
||||
if (_variable.isFileLevelVariable() && !_variable.isConstant())
|
||||
m_errorReporter.declarationError(
|
||||
8342_error,
|
||||
_variable.location(),
|
||||
"Only constant variables are allowed at file level."
|
||||
);
|
||||
if (_variable.isConstant() && (!_variable.isStateVariable() && !_variable.isFileLevelVariable()))
|
||||
m_errorReporter.declarationError(
|
||||
1788_error,
|
||||
_variable.location(),
|
||||
"The \"constant\" keyword can only be used for state variables."
|
||||
"The \"constant\" keyword can only be used for state variables or variables at file level."
|
||||
);
|
||||
if (_variable.immutable() && !_variable.isStateVariable())
|
||||
m_errorReporter.declarationError(
|
||||
@@ -344,6 +350,11 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable)
|
||||
solAssert(varLoc == Location::Unspecified, "");
|
||||
typeLoc = DataLocation::Memory;
|
||||
}
|
||||
else if (_variable.isFileLevelVariable())
|
||||
{
|
||||
solAssert(varLoc == Location::Unspecified, "");
|
||||
typeLoc = DataLocation::Memory;
|
||||
}
|
||||
else if (_variable.isStateVariable())
|
||||
{
|
||||
solAssert(varLoc == Location::Unspecified, "");
|
||||
|
||||
@@ -87,7 +87,7 @@ bool DocStringAnalyser::visit(FunctionDefinition const& _function)
|
||||
|
||||
bool DocStringAnalyser::visit(VariableDeclaration const& _variable)
|
||||
{
|
||||
if (!_variable.isStateVariable())
|
||||
if (!_variable.isStateVariable() && !_variable.isFileLevelVariable())
|
||||
return false;
|
||||
|
||||
if (CallableDeclaration const* baseFunction = resolveInheritDoc(_variable.annotation().baseFunctions, _variable, _variable.annotation()))
|
||||
|
||||
@@ -61,13 +61,13 @@ bool DocStringTagParser::visit(VariableDeclaration const& _variable)
|
||||
{
|
||||
if (_variable.isStateVariable())
|
||||
{
|
||||
static set<string> const validPublicTags = set<string>{"dev", "notice", "return", "inheritdoc"};
|
||||
static set<string> const validNonPublicTags = set<string>{"dev", "inheritdoc"};
|
||||
if (_variable.isPublic())
|
||||
parseDocStrings(_variable, _variable.annotation(), validPublicTags, "public state variables");
|
||||
parseDocStrings(_variable, _variable.annotation(), {"dev", "notice", "return", "inheritdoc"}, "public state variables");
|
||||
else
|
||||
parseDocStrings(_variable, _variable.annotation(), validNonPublicTags, "non-public state variables");
|
||||
parseDocStrings(_variable, _variable.annotation(), {"dev", "inheritdoc"}, "non-public state variables");
|
||||
}
|
||||
else if (_variable.isFileLevelVariable())
|
||||
parseDocStrings(_variable, _variable.annotation(), {"dev"}, "file-level variables");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace solidity::frontend
|
||||
|
||||
/**
|
||||
* This module performs analyses on the AST that are done after type checking and assignments of types:
|
||||
* - whether there are circular references in constant state variables
|
||||
* - whether there are circular references in constant variables
|
||||
* - whether override specifiers are actually contracts
|
||||
* - whether a modifier is in a function header
|
||||
* - whether an event is used outside of an emit statement
|
||||
|
||||
Reference in New Issue
Block a user