diff options
author | Erik Kundt <bitshift@posteo.org> | 2018-06-27 18:29:03 +0800 |
---|---|---|
committer | Erik Kundt <bitshift@posteo.org> | 2018-07-18 20:29:01 +0800 |
commit | 182a0a95516e4f218524b929035e6a1bd5d2742c (patch) | |
tree | bcf6743a43070346a5193f1a4d9d12c3b5bd092c /libsolidity/analysis | |
parent | b909df4573130e020c7f4dfb61c0571ba1bc02ab (diff) | |
download | dexon-solidity-182a0a95516e4f218524b929035e6a1bd5d2742c.tar.gz dexon-solidity-182a0a95516e4f218524b929035e6a1bd5d2742c.tar.zst dexon-solidity-182a0a95516e4f218524b929035e6a1bd5d2742c.zip |
Disallows old constructor syntax.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/NameAndTypeResolver.cpp | 14 | ||||
-rw-r--r-- | libsolidity/analysis/SyntaxChecker.cpp | 28 |
2 files changed, 17 insertions, 25 deletions
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index 7c23c992..e0880ec9 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -482,7 +482,15 @@ bool DeclarationRegistrationHelper::registerDeclaration( Declaration const* shadowedDeclaration = nullptr; if (_warnOnShadow && !name.empty() && _container.enclosingContainer()) for (auto const* decl: _container.enclosingContainer()->resolveName(name, true, true)) - shadowedDeclaration = decl; + // Do not warn about functions shadowing a contract. + if ( + !( + dynamic_cast<ContractDefinition const*>(decl) && + dynamic_cast<FunctionDefinition const*>(&_declaration) && + name == decl->name() + ) + ) + shadowedDeclaration = decl; // We use "invisible" for both inactive variables in blocks and for members invisible in contracts. // They cannot both be true at the same time. @@ -710,10 +718,6 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio dynamic_cast<EventDefinition const*>(m_currentScope) ) warnAboutShadowing = false; - // Do not warn about the constructor shadowing the contract. - if (auto fun = dynamic_cast<FunctionDefinition const*>(&_declaration)) - if (fun->isConstructor()) - warnAboutShadowing = false; // Register declaration as inactive if we are in block scope. bool inactive = diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 4d09e36d..5d16a33f 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -200,6 +200,14 @@ bool SyntaxChecker::visit(PlaceholderStatement const&) bool SyntaxChecker::visit(ContractDefinition const& _contract) { m_isInterface = _contract.contractKind() == ContractDefinition::ContractKind::Interface; + + ASTString const& contractName = _contract.name(); + for (FunctionDefinition const* function: _contract.definedFunctions()) + if (function->name() == contractName) + m_errorReporter.syntaxError(function->location(), + "Functions are not allowed to have the same name as the contract. " + "If you intend this to be a constructor, use \"constructor(...) { ... }\" to define it." + ); return true; } @@ -216,21 +224,6 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function) ); } - if (_function.isOldStyleConstructor()) - { - if (v050) - m_errorReporter.syntaxError( - _function.location(), - "Functions are not allowed to have the same name as the contract. " - "If you intend this to be a constructor, use \"constructor(...) { ... }\" to define it." - ); - else - m_errorReporter.warning( - _function.location(), - "Defining constructors as functions with the same name as the contract is deprecated. " - "Use \"constructor(...) { ... }\" instead." - ); - } if (!_function.isImplemented() && !_function.modifiers().empty()) { if (v050) @@ -238,11 +231,6 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function) else m_errorReporter.warning(_function.location(), "Modifiers of functions without implementation are ignored." ); } - if (_function.name() == "constructor") - m_errorReporter.warning(_function.location(), - "This function is named \"constructor\" but is not the constructor of the contract. " - "If you intend this to be a constructor, use \"constructor(...) { ... }\" without the \"function\" keyword to define it." - ); return true; } |