Skip to content

Commit 13691df

Browse files
authored
Merge pull request #11628 from ethereum/noOverrideForInterface
Add override exception for interface functions.
2 parents 78afd71 + f7916f2 commit 13691df

22 files changed

+83
-38
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 0.8.8 (unreleased)
22

33
Language Features:
4+
* Inheritance: A function that overrides only a single interface function does not require the ``override`` specifier.
45

56

67
Compiler Features:

docs/contracts/inheritance.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ contracts can no longer change the behaviour of that function.
303303
outside of interfaces. In interfaces, all functions are
304304
automatically considered ``virtual``.
305305

306+
.. note::
307+
308+
Starting from Solidity 0.8.8, the ``override`` keyword is not
309+
required when overriding an interface function, except for the
310+
case where the function is defined in multiple bases.
311+
312+
306313
Public state variables can override external functions if the
307314
parameter and return types of the function matches the getter function
308315
of the variable:

docs/contracts/interfaces.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ Interfaces are denoted by their own keyword:
3333
3434
Contracts can inherit interfaces as they would inherit other contracts.
3535

36-
All functions declared in interfaces are implicitly ``virtual``, which means that
37-
they can be overridden. This does not automatically mean that an overriding function
38-
can be overridden again - this is only possible if the overriding
39-
function is marked ``virtual``.
36+
All functions declared in interfaces are implicitly ``virtual`` and any
37+
functions that override them do not need the ``override`` keyword.
38+
This does not automatically mean that an overriding function can be overridden again -
39+
this is only possible if the overriding function is marked ``virtual``.
4040

4141
Interfaces can inherit from other interfaces. This has the same rules as normal
4242
inheritance.

libsolidity/analysis/OverrideChecker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ struct OverrideGraph
8686
int currentNode = static_cast<int>(numNodes++);
8787
nodes[_function] = currentNode;
8888
nodeInv[currentNode] = _function;
89-
if (_function.overrides())
89+
90+
if (!_function.baseFunctions().empty())
9091
for (auto const& baseFunction: _function.baseFunctions())
9192
addEdge(currentNode, visit(baseFunction));
9293
else
@@ -518,7 +519,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
518519
"Override changes modifier signature."
519520
);
520521

521-
if (!_overriding.overrides())
522+
if (!_overriding.overrides() && !(_super.isFunction() && _super.contract().isInterface()))
522523
overrideError(
523524
_overriding,
524525
_super,

test/libsolidity/syntaxTests/inheritance/interface/overrides_multiple.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ interface Sub is SuperA, SuperB {
2323
}
2424

2525
// ----
26-
// TypeError 9456: (572-616): Overriding function is missing "override" specifier.
27-
// TypeError 9456: (572-616): Overriding function is missing "override" specifier.
2826
// TypeError 4327: (572-616): Function needs to specify overridden contracts "SuperA" and "SuperB".
2927
// TypeError 4327: (647-655): Function needs to specify overridden contracts "SuperA" and "SuperB".
3028
// TypeError 4327: (705-721): Function needs to specify overridden contract "SuperB".

test/libsolidity/syntaxTests/inheritance/interface/overrides_single.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ interface Sub is Super {
1111
}
1212

1313
// ----
14-
// TypeError 9456: (197-241): Overriding function is missing "override" specifier.

test/libsolidity/syntaxTests/inheritance/override/calldata_memory_interface.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ interface I {
66
}
77
contract C is I {
88
uint dummy;
9-
function f(uint[] memory) public override pure {}
10-
function g(uint[] memory) public override view { dummy; }
11-
function h(uint[] memory) public override { dummy = 42; }
12-
function i(uint[] memory) public override payable {}
9+
function f(uint[] memory) public pure {}
10+
function g(uint[] memory) public view { dummy; }
11+
function h(uint[] memory) public { dummy = 42; }
12+
function i(uint[] memory) public payable {}
1313
}
1414
// ----

test/libsolidity/syntaxTests/inheritance/override/calldata_memory_interface_instantiate.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface I {
22
function f(uint[] calldata) external pure;
33
}
44
contract A is I {
5-
function f(uint[] memory) public override pure {}
5+
function f(uint[] memory) public pure {}
66
}
77
contract C {
88
function f() public {

test/libsolidity/syntaxTests/inheritance/override/calldata_memory_interface_struct.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface I {
99
contract C is I {
1010
uint dummy;
1111
function f(S memory) public override pure {}
12-
function g(S memory) public override view { dummy; }
12+
function g(S memory) public view { dummy; }
1313
function h(S memory) public override { dummy = 42; }
14-
function i(S memory) public override payable {}
14+
function i(S memory) public payable {}
1515
}
1616
// ----

test/libsolidity/syntaxTests/inheritance/override/change_return_types_in_interface.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ contract B is I {
77
function f() public pure returns (uint, uint) {}
88
}
99
// ----
10-
// TypeError 9456: (182-230): Overriding function is missing "override" specifier.
1110
// TypeError 4822: (182-230): Overriding function return types differ.

0 commit comments

Comments
 (0)