Skip to content

Commit

Permalink
Warn about functions named "constructor".
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Apr 18, 2018
1 parent cd17c37 commit 4895864
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
### 0.4.23 (unreleased)

Features:
* SMTChecker: Integration with CVC4 SMT solver
* Build system: Support Ubuntu Bionic.
* SMTChecker: Integration with CVC4 SMT solver
* Syntax Checker: Warn about functions named "constructor".

Bugfixes:
* Type Checker: Do not complain about new-style constructor and fallback function to have the same name.
Expand Down
7 changes: 6 additions & 1 deletion libsolidity/analysis/SyntaxChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,13 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
if (v050)
m_errorReporter.syntaxError(_function.location(), "Functions without implementation cannot have modifiers.");
else
m_errorReporter.warning( _function.location(), "Modifiers of functions without implementation are ignored." );
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function constructor() public;
}
// ----
// Warning: (17-47): 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.

0 comments on commit 4895864

Please sign in to comment.