Constants are considered pure.

This commit is contained in:
chriseth 2020-07-14 20:18:34 +02:00 committed by Mathias Baumann
parent d3647b13e4
commit c8772a54c3
4 changed files with 17 additions and 1 deletions

View File

@ -30,6 +30,7 @@ Compiler Features:
Bugfixes:
* NatSpec: Constructors and functions have consistent userdoc output.
* Inheritance: Disallow public state variables overwriting ``pure`` functions.
* State Mutability: Constant public state variables are considered ``pure`` functions.
### 0.6.12 (unreleased)

View File

@ -289,7 +289,7 @@ StateMutability OverrideProxy::stateMutability() const
return std::visit(GenericVisitor{
[&](FunctionDefinition const* _item) { return _item->stateMutability(); },
[&](ModifierDefinition const*) { solAssert(false, "Requested state mutability from modifier."); return StateMutability{}; },
[&](VariableDeclaration const*) { return StateMutability::View; }
[&](VariableDeclaration const* _var) { return _var->isConstant() ? StateMutability::Pure : StateMutability::View; }
}, m_item);
}

View File

@ -0,0 +1,7 @@
abstract contract C {
function foo() external pure virtual returns (uint);
}
contract X is C {
uint public constant override foo = 7;
}
// ----

View File

@ -0,0 +1,8 @@
abstract contract C {
function foo() external pure virtual returns (uint);
}
contract X is C {
uint public immutable override foo = 7;
}
// ----
// TypeError 6959: (100-124): Overriding public state variable changes state mutability from "pure" to "view".