Merge pull request #9750 from ethereum/virtual-library-modifier

Type Checker: Disallow ``virtual`` for modifiers in libraries.
This commit is contained in:
chriseth 2020-09-07 14:05:10 +02:00 committed by GitHub
commit 2b29f4e56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Compiler Features:
* Yul Optimizer: Prune unused parameters in functions. * Yul Optimizer: Prune unused parameters in functions.
Bugfixes: Bugfixes:
* Type Checker: Disallow ``virtual`` for modifiers in libraries.
### 0.7.1 (2020-09-02) ### 0.7.1 (2020-09-02)

View File

@ -320,6 +320,15 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance)
void TypeChecker::endVisit(ModifierDefinition const& _modifier) void TypeChecker::endVisit(ModifierDefinition const& _modifier)
{ {
if (_modifier.virtualSemantics())
if (auto const* contractDef = dynamic_cast<ContractDefinition const*>(_modifier.scope()))
if (contractDef->isLibrary())
m_errorReporter.typeError(
3275_error,
_modifier.location(),
"Modifiers in a library cannot be virtual."
);
if (!_modifier.isImplemented() && !_modifier.virtualSemantics()) if (!_modifier.isImplemented() && !_modifier.virtualSemantics())
m_errorReporter.typeError(8063_error, _modifier.location(), "Modifiers without implementation must be marked virtual."); m_errorReporter.typeError(8063_error, _modifier.location(), "Modifiers without implementation must be marked virtual.");
} }

View File

@ -0,0 +1,7 @@
library test {
modifier m virtual;
function f() m public {
}
}
// ----
// TypeError 3275: (19-38): Modifiers in a library cannot be virtual.