Skip to content

Commit e5500b9

Browse files
authored
Merge pull request #11471 from ethereum/funcdef-unimplemented-modifier
Reports an error on unimplemented modifiers in a function definition.
2 parents 0fff4e6 + a14ac19 commit e5500b9

File tree

7 files changed

+63
-8
lines changed

7 files changed

+63
-8
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Bugfixes:
3232
* Type Checker: Fix internal compiler error when attempting to use an invalid external function type on pre-byzantium EVMs.
3333
* Type Checker: Make errors about (nested) mapping type in event or error parameter into fatal type errors.
3434
* Type Checker: Fix internal compiler error when overriding receive ether function with one having different parameters during inheritance.
35+
* Type Checker: Fix internal compiler error when overriding an implemented modifier with an unimplemented one.
3536

3637

3738
AST Changes:

libsolidity/analysis/OverrideChecker.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
573573
);
574574
}
575575

576+
if (_overriding.unimplemented() && !_super.unimplemented())
577+
{
578+
solAssert(!_overriding.isVariable() || !_overriding.unimplemented(), "");
579+
overrideError(
580+
_overriding,
581+
_super,
582+
4593_error,
583+
"Overriding an implemented " + _super.astNodeName() +
584+
" with an unimplemented " + _overriding.astNodeName() +
585+
" is not allowed."
586+
);
587+
}
588+
576589
if (_super.isFunction())
577590
{
578591
FunctionType const* functionType = _overriding.functionType();
@@ -613,14 +626,6 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
613626
stateMutabilityToString(_overriding.stateMutability()) +
614627
"\"."
615628
);
616-
617-
if (_overriding.unimplemented() && !_super.unimplemented())
618-
overrideError(
619-
_overriding,
620-
_super,
621-
4593_error,
622-
"Overriding an implemented function with an unimplemented function is not allowed."
623-
);
624629
}
625630
}
626631

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract A {
2+
modifier m() virtual { _; }
3+
}
4+
abstract contract B is A {
5+
modifier m() virtual override;
6+
}
7+
contract C is B {
8+
function f() m public {}
9+
}
10+
// ----
11+
// TypeError 4593: (78-108): Overriding an implemented modifier with an unimplemented modifier is not allowed.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract A {
2+
modifier m() virtual { _; }
3+
}
4+
abstract contract B {
5+
modifier m() virtual;
6+
}
7+
contract C is A, B {
8+
modifier m() override(A, B) { _; }
9+
function f() m public {}
10+
}
11+
// ----
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
abstract contract A {
2+
modifier m() virtual;
3+
}
4+
abstract contract B is A {
5+
modifier m() virtual override;
6+
}
7+
abstract contract C is B {
8+
modifier m() virtual override;
9+
function f() m public {}
10+
}
11+
// ----
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
abstract contract A {
2+
modifier m() virtual;
3+
function f() m public {}
4+
}
5+
contract B is A {
6+
modifier m() virtual override { _; }
7+
}
8+
// ----
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
abstract contract A {
2+
modifier m() virtual;
3+
function f() m public virtual {}
4+
}
5+
abstract contract B is A {
6+
function f() public override {}
7+
}
8+
// ----

0 commit comments

Comments
 (0)