Merge pull request #9418 from ethereum/stateMutForOverride

Issue state mutability restriction for overriding and not for virtual functions.
This commit is contained in:
Mathias L. Baumann 2020-07-20 15:01:25 +02:00 committed by GitHub
commit 69a596b0ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 16 deletions

View File

@ -19,6 +19,7 @@ Breaking changes:
* Remove the finney and szabo denominations.
Language Features:
* State mutability: Do not issue recommendation for stricter mutability for virtual functions but do issue it for functions that override.
* Yul: Disallow EVM instruction `pc()`.
* Yul: Disallow consecutive and trailing dots in identifiers. Leading dots were already disallowed.
* Inheritance: Allow overrides to have stricter state mutability: ``view`` can override ``nonpayable`` and ``pure`` can override ``view``.

View File

@ -27,11 +27,11 @@ all defined functions. The usage of an abstract contract as a base class is show
pragma solidity >=0.6.0 <0.8.0;
abstract contract Feline {
function utterance() public virtual returns (bytes32);
function utterance() public pure virtual returns (bytes32);
}
contract Cat is Feline {
function utterance() public override returns (bytes32) { return "miaow"; }
function utterance() public pure override returns (bytes32) { return "miaow"; }
}
If a contract inherits from an abstract contract and does not implement all non-implemented

View File

@ -168,7 +168,7 @@ void ViewPureChecker::endVisit(FunctionDefinition const& _funDef)
!_funDef.isConstructor() &&
!_funDef.isFallback() &&
!_funDef.isReceive() &&
!_funDef.overrides()
!_funDef.virtualSemantics()
)
m_errorReporter.warning(
2018_error,

View File

@ -1,10 +1,10 @@
interface Parent {
function test() external returns (uint256);
function test() external pure returns (uint256);
}
interface SubA is Parent {}
interface SubB is Parent {}
contract C is SubA, SubB {
function test() external override returns (uint256) { return 42; }
function test() external override pure returns (uint256) { return 42; }
}

View File

@ -1,15 +1,15 @@
interface Parent {
function test() external returns (uint256);
function test() external pure returns (uint256);
}
interface SubA is Parent {
function test() external override returns (uint256);
function test() external pure override returns (uint256);
}
interface SubB is Parent {
function test() external override returns (uint256);
function test() external pure override returns (uint256);
}
contract C is SubA, SubB {
function test() external override(SubA, SubB) returns (uint256) { return 42; }
function test() external pure override(SubA, SubB) returns (uint256) { return 42; }
}

View File

@ -1,17 +1,17 @@
interface ParentA {
function testA() external returns (uint256);
function testA() external pure returns (uint256);
}
interface ParentB {
function testB() external returns (uint256);
function testB() external pure returns (uint256);
}
interface Sub is ParentA, ParentB {
function testSub() external returns (uint256);
function testSub() external pure returns (uint256);
}
contract SubImpl is Sub {
function testA() external override returns (uint256) { return 12; }
function testB() external override(ParentB) returns (uint256) { return 42; }
function testSub() external override returns (uint256) { return 99; }
function testA() external pure override returns (uint256) { return 12; }
function testB() external pure override(ParentB) returns (uint256) { return 42; }
function testSub() external pure override returns (uint256) { return 99; }
}

View File

@ -0,0 +1,14 @@
contract A {
// no "state mutability can be restricted"-warning here
function foo() external virtual returns (uint) { return 1; }
}
contract B is A {
// no "state mutability can be restricted"-warning here
function foo() external virtual override returns (uint) { return 2; }
}
contract C is B {
// warning is here
function foo() external override returns (uint) { return 3; }
}
// ----
// Warning 2018: (339-400): Function state mutability can be restricted to pure

View File

@ -5,4 +5,4 @@ contract Bike is Vehicle {
function f(bytes calldata) override external returns (uint256 r) {r = 42;}
}
// ----
// Warning 2018: (23-95): Function state mutability can be restricted to pure
// Warning 2018: (129-203): Function state mutability can be restricted to pure