aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp8
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp15
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default.sol6
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default050.sol7
4 files changed, 24 insertions, 12 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index 6aee260e..20464765 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -50,6 +50,14 @@ 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 \"" +
+ (isInterface ? "external" : Declaration::visibilityToString(_function.visibility())) +
+ "\"."
+ );
if (_function.isImplemented())
m_currentFunction = &_function;
else
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index ddac194b..5de9a270 100644
--- a/libsolidity/analysis/SyntaxChecker.cpp
+++ b/libsolidity/analysis/SyntaxChecker.cpp
@@ -214,18 +214,9 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
{
bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050);
- if (_function.noVisibilitySpecified())
- {
- if (v050)
- m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
- else
- m_errorReporter.warning(
- _function.location(),
- "No visibility specified. Defaulting to \"" +
- Declaration::visibilityToString(_function.visibility()) +
- "\"."
- );
- }
+ if (v050 && _function.noVisibilitySpecified())
+ m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
+
return true;
}
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
new file mode 100644
index 00000000..9889d038
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
@@ -0,0 +1,6 @@
+interface I {
+ function f();
+}
+// ----
+// Warning: Functions in interfaces should be declared external.
+// Warning: No visibility specified. Defaulting to "external".
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
new file mode 100644
index 00000000..127d4e92
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default050.sol
@@ -0,0 +1,7 @@
+pragma experimental "v0.5.0";
+interface I {
+ function f();
+}
+// ----
+// SyntaxError: No visibility specified.
+// TypeError: Functions in interfaces must be declared external.