diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-04-04 18:28:22 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-04-09 21:26:05 +0800 |
commit | b8fdb666e235bb6b19f11dba7740227026111598 (patch) | |
tree | 052d6a730b300e6c976759ac993d879153082c08 /libsolidity/analysis | |
parent | 4e037281acaf74c907f68e6227d6aa1b8847c78d (diff) | |
download | dexon-solidity-b8fdb666e235bb6b19f11dba7740227026111598.tar.gz dexon-solidity-b8fdb666e235bb6b19f11dba7740227026111598.tar.zst dexon-solidity-b8fdb666e235bb6b19f11dba7740227026111598.zip |
Allow duplicated constructor calls, if no arguments; support for multiple inheritance; backwards compatibility.
# tmp
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 6c70ba6b..700c8a71 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -90,33 +90,43 @@ 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; + bool const v050 = m_currentContract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); + if (auto contract = dynamic_cast<ContractDefinition const*>(_modifier.name()->annotation().referencedDeclaration)) - for (auto const& specifier: m_currentContract->baseContracts()) - if (modifierOverridesInheritanceSpecifier(contract, _modifier, *specifier)) + for (auto const& base: m_currentContract->annotation().linearizedBaseContracts) + for (auto const& specifier: base->baseContracts()) { - SecondarySourceLocation ssl; - ssl.append("Overriden constructor call is here:", specifier->location()); - - m_errorReporter.declarationError( - _modifier.location(), - ssl, - "Duplicated super constructor call." - ); + Declaration const* parent = specifier->name().annotation().referencedDeclaration; + if (contract == parent && !specifier->arguments().empty()) + { + if (v050) + { + SecondarySourceLocation ssl; + ssl.append("Second constructor call is here:", specifier->location()); + + m_errorReporter.declarationError( + _modifier.location(), + ssl, + "Duplicated super constructor call." + ); + } + else + { + SecondarySourceLocation ssl; + ssl.append("Overridden constructor call is here:", specifier->location()); + + m_errorReporter.warning( + _modifier.location(), + "Duplicated super constructor calls are deprecated.", + ssl + ); + } + } } return true; |