mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow duplicated constructor calls, if no arguments; support for multiple inheritance; backwards compatibility.
# tmp
This commit is contained in:
@@ -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;
|
||||
|
||||
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());
|
||||
bool const v050 = m_currentContract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
|
||||
|
||||
m_errorReporter.declarationError(
|
||||
_modifier.location(),
|
||||
ssl,
|
||||
"Duplicated super constructor call."
|
||||
);
|
||||
if (auto contract = dynamic_cast<ContractDefinition const*>(_modifier.name()->annotation().referencedDeclaration))
|
||||
for (auto const& base: m_currentContract->annotation().linearizedBaseContracts)
|
||||
for (auto const& specifier: base->baseContracts())
|
||||
{
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user