diff options
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.cpp | 32 | ||||
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.h | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 33b0e296..6c70ba6b 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -90,6 +90,38 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&) m_localVarUseCount.clear(); } +bool modifierOverridesInheritanceSpecifier( + ContractDefinition const* _contract, + ModifierInvocation const& _modifier, + InheritanceSpecifier const& _specifier +) +{ + auto parent = _specifier.name().annotation().referencedDeclaration; + return _contract == parent && (!_specifier.arguments().empty() || _modifier.arguments().empty()); +} + +bool StaticAnalyzer::visit(ModifierInvocation const& _modifier) +{ + if (!m_constructor) + return true; + + if (auto contract = dynamic_cast<ContractDefinition const*>(_modifier.name()->annotation().referencedDeclaration)) + for (auto const& specifier: m_currentContract->baseContracts()) + if (modifierOverridesInheritanceSpecifier(contract, _modifier, *specifier)) + { + SecondarySourceLocation ssl; + ssl.append("Overriden constructor call is here:", specifier->location()); + + m_errorReporter.declarationError( + _modifier.location(), + ssl, + "Duplicated super constructor call." + ); + } + + return true; +} + bool StaticAnalyzer::visit(Identifier const& _identifier) { if (m_currentFunction) diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h index 0a806bbd..e68325bc 100644 --- a/libsolidity/analysis/StaticAnalyzer.h +++ b/libsolidity/analysis/StaticAnalyzer.h @@ -57,6 +57,7 @@ private: virtual bool visit(FunctionDefinition const& _function) override; virtual void endVisit(FunctionDefinition const& _function) override; + virtual bool visit(ModifierInvocation const& _modifier) override; virtual bool visit(ExpressionStatement const& _statement) override; virtual bool visit(VariableDeclaration const& _variable) override; |