mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow public state variables overriding pure functions.
This commit is contained in:
parent
69a596b0ff
commit
d3647b13e4
@ -29,6 +29,7 @@ Compiler Features:
|
||||
|
||||
Bugfixes:
|
||||
* NatSpec: Constructors and functions have consistent userdoc output.
|
||||
* Inheritance: Disallow public state variables overwriting ``pure`` functions.
|
||||
|
||||
|
||||
### 0.6.12 (unreleased)
|
||||
|
@ -310,7 +310,7 @@ of the variable:
|
||||
|
||||
contract A
|
||||
{
|
||||
function f() external pure virtual returns(uint) { return 5; }
|
||||
function f() external view virtual returns(uint) { return 5; }
|
||||
}
|
||||
|
||||
contract B is A
|
||||
|
@ -584,11 +584,10 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
|
||||
"Overridden " + _overriding.astNodeName() + " is here:"
|
||||
);
|
||||
|
||||
// This is only relevant for a function overriding a function.
|
||||
if (_overriding.isFunction())
|
||||
{
|
||||
// Stricter mutability is always okay except when super is Payable
|
||||
if ((
|
||||
if (
|
||||
(_overriding.isFunction() || _overriding.isVariable()) &&
|
||||
(
|
||||
_overriding.stateMutability() > _super.stateMutability() ||
|
||||
_super.stateMutability() == StateMutability::Payable
|
||||
) &&
|
||||
@ -598,7 +597,9 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
|
||||
_overriding,
|
||||
_super,
|
||||
6959_error,
|
||||
"Overriding function changes state mutability from \"" +
|
||||
"Overriding " +
|
||||
_overriding.astNodeName() +
|
||||
" changes state mutability from \"" +
|
||||
stateMutabilityToString(_super.stateMutability()) +
|
||||
"\" to \"" +
|
||||
stateMutabilityToString(_overriding.stateMutability()) +
|
||||
@ -614,7 +615,6 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverrideChecker::overrideListError(
|
||||
OverrideProxy const& _item,
|
||||
|
@ -0,0 +1,8 @@
|
||||
abstract contract C {
|
||||
function foo() external pure virtual returns (uint);
|
||||
}
|
||||
contract X is C {
|
||||
uint public override foo;
|
||||
}
|
||||
// ----
|
||||
// TypeError 6959: (100-124): Overriding public state variable changes state mutability from "pure" to "view".
|
Loading…
Reference in New Issue
Block a user