aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-07-18 18:08:42 +0800
committerGitHub <noreply@github.com>2018-07-18 18:08:42 +0800
commitb909df4573130e020c7f4dfb61c0571ba1bc02ab (patch)
treec5657726547d314fef6e80af702d061275afe5c7 /libsolidity
parent1d33f41c1ab96746b97b97f79732ec23759fb8f0 (diff)
parent8b827af5bf4ed52c9612bcf1bdadb25ca7b879bf (diff)
downloaddexon-solidity-b909df4573130e020c7f4dfb61c0571ba1bc02ab.tar.gz
dexon-solidity-b909df4573130e020c7f4dfb61c0571ba1bc02ab.tar.zst
dexon-solidity-b909df4573130e020c7f4dfb61c0571ba1bc02ab.zip
Merge pull request #4430 from ethereum/enforceVisibilitySpecifier
[BREAKING] Enforce visibility specifier
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp10
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp16
-rw-r--r--libsolidity/analysis/SyntaxChecker.h2
3 files changed, 16 insertions, 12 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index 323282ca..60a58665 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -51,16 +51,6 @@ void StaticAnalyzer::endVisit(ContractDefinition const&)
bool StaticAnalyzer::visit(FunctionDefinition const& _function)
{
- const bool isInterface = m_currentContract->contractKind() == ContractDefinition::ContractKind::Interface;
-
- if (_function.noVisibilitySpecified())
- m_errorReporter.warning(
- _function.location(),
- "No visibility specified. Defaulting to \"" +
- Declaration::visibilityToString(_function.visibility()) +
- "\"." +
- (isInterface ? " In interfaces it defaults to external." : "")
- );
if (_function.isImplemented())
m_currentFunction = &_function;
else
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index fba18a45..4d09e36d 100644
--- a/libsolidity/analysis/SyntaxChecker.cpp
+++ b/libsolidity/analysis/SyntaxChecker.cpp
@@ -197,12 +197,24 @@ bool SyntaxChecker::visit(PlaceholderStatement const&)
return true;
}
+bool SyntaxChecker::visit(ContractDefinition const& _contract)
+{
+ m_isInterface = _contract.contractKind() == ContractDefinition::ContractKind::Interface;
+ return true;
+}
+
bool SyntaxChecker::visit(FunctionDefinition const& _function)
{
bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050);
- if (v050 && _function.noVisibilitySpecified())
- m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
+ if (_function.noVisibilitySpecified())
+ {
+ string suggestedVisibility = _function.isFallback() || m_isInterface ? "external" : "public";
+ m_errorReporter.syntaxError(
+ _function.location(),
+ "No visibility specified. Did you intend to add \"" + suggestedVisibility + "\"?"
+ );
+ }
if (_function.isOldStyleConstructor())
{
diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h
index 5460e3be..28a0f66e 100644
--- a/libsolidity/analysis/SyntaxChecker.h
+++ b/libsolidity/analysis/SyntaxChecker.h
@@ -66,6 +66,7 @@ private:
virtual bool visit(PlaceholderStatement const& _placeholderStatement) override;
+ virtual bool visit(ContractDefinition const& _contract) override;
virtual bool visit(FunctionDefinition const& _function) override;
virtual bool visit(FunctionTypeName const& _node) override;
@@ -82,6 +83,7 @@ private:
bool m_versionPragmaFound = false;
int m_inLoopDepth = 0;
+ bool m_isInterface = false;
SourceUnit const* m_sourceUnit = nullptr;
};