Allow constant variables in pure functions.

This commit is contained in:
chriseth 2017-09-05 18:33:52 +02:00
parent 15bdc48a73
commit b756274357
2 changed files with 14 additions and 1 deletions

View File

@ -179,7 +179,7 @@ void ViewPureChecker::endVisit(Identifier const& _identifier)
bool writes = _identifier.annotation().lValueRequested;
if (VariableDeclaration const* varDecl = dynamic_cast<VariableDeclaration const*>(declaration))
{
if (varDecl->isStateVariable())
if (varDecl->isStateVariable() && !varDecl->isConstant())
mutability = writes ? StateMutability::NonPayable : StateMutability::View;
}
else if (MagicVariableDeclaration const* magicVar = dynamic_cast<MagicVariableDeclaration const*>(declaration))

View File

@ -378,6 +378,19 @@ BOOST_AUTO_TEST_CASE(assembly_jump)
CHECK_WARNING(text, "low-level EVM features");
}
BOOST_AUTO_TEST_CASE(constant)
{
string text = R"(
contract C {
uint constant x = 2;
function k() pure returns (uint) {
return x;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_SUITE_END()
}