diff --git a/Changelog.md b/Changelog.md index fa16c516f..0970a3b0c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Compiler Features: * Yul Optimizer: Prune unused parameters in functions. Bugfixes: + * Type Checker: Disallow ``virtual`` for modifiers in libraries. ### 0.7.1 (2020-09-02) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 990192d68..2f9768d9a 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -320,6 +320,15 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance) void TypeChecker::endVisit(ModifierDefinition const& _modifier) { + if (_modifier.virtualSemantics()) + if (auto const* contractDef = dynamic_cast(_modifier.scope())) + if (contractDef->isLibrary()) + m_errorReporter.typeError( + 3275_error, + _modifier.location(), + "Modifiers in a library cannot be virtual." + ); + if (!_modifier.isImplemented() && !_modifier.virtualSemantics()) m_errorReporter.typeError(8063_error, _modifier.location(), "Modifiers without implementation must be marked virtual."); } diff --git a/test/libsolidity/syntaxTests/inheritance/virtual/modifier_virtual_err.sol b/test/libsolidity/syntaxTests/inheritance/virtual/modifier_virtual_err.sol new file mode 100644 index 000000000..85824c86b --- /dev/null +++ b/test/libsolidity/syntaxTests/inheritance/virtual/modifier_virtual_err.sol @@ -0,0 +1,7 @@ +library test { + modifier m virtual; + function f() m public { + } +} +// ---- +// TypeError 3275: (19-38): Modifiers in a library cannot be virtual.