From b756274357c1e33517d535fdd2349a88221d4780 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 5 Sep 2017 18:33:52 +0200 Subject: Allow constant variables in pure functions. --- libsolidity/analysis/ViewPureChecker.cpp | 2 +- test/libsolidity/ViewPureChecker.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index 6621edb1..d4a6e96f 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -179,7 +179,7 @@ void ViewPureChecker::endVisit(Identifier const& _identifier) bool writes = _identifier.annotation().lValueRequested; if (VariableDeclaration const* varDecl = dynamic_cast(declaration)) { - if (varDecl->isStateVariable()) + if (varDecl->isStateVariable() && !varDecl->isConstant()) mutability = writes ? StateMutability::NonPayable : StateMutability::View; } else if (MagicVariableDeclaration const* magicVar = dynamic_cast(declaration)) diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 6e99260c..9cea9850 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -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() } -- cgit v1.2.3