aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsolidity/analysis/SyntaxChecker.cpp14
-rw-r--r--libsolidity/analysis/SyntaxChecker.h2
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol2
-rw-r--r--test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol2
-rw-r--r--test/libsolidity/syntaxTests/fallback/default_visibility.sol2
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol2
-rw-r--r--test/libsolidity/syntaxTests/visibility/function_no_visibility.sol2
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/function_default.sol2
-rw-r--r--test/libsolidity/syntaxTests/visibility/interface/interface_contract_function_default.sol10
9 files changed, 31 insertions, 7 deletions
diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp
index 234c177c..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 (_function.noVisibilitySpecified())
- m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
+ {
+ 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;
};
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol
index 3835560a..586329b1 100644
--- a/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol
+++ b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility.sol
@@ -1,3 +1,3 @@
contract A { constructor() {} }
// ----
-// SyntaxError: (13-29): No visibility specified.
+// SyntaxError: (13-29): No visibility specified. Did you intend to add "public"?
diff --git a/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol
index 0f57a41f..9f60f0d8 100644
--- a/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol
+++ b/test/libsolidity/syntaxTests/constructor/constructor_no_visibility_050.sol
@@ -1,4 +1,4 @@
pragma experimental "v0.5.0";
contract A { constructor() {} }
// ----
-// SyntaxError: (43-59): No visibility specified.
+// SyntaxError: (43-59): No visibility specified. Did you intend to add "public"?
diff --git a/test/libsolidity/syntaxTests/fallback/default_visibility.sol b/test/libsolidity/syntaxTests/fallback/default_visibility.sol
index 2199a99b..6fbb15a5 100644
--- a/test/libsolidity/syntaxTests/fallback/default_visibility.sol
+++ b/test/libsolidity/syntaxTests/fallback/default_visibility.sol
@@ -3,5 +3,5 @@ contract C {
function() {}
}
// ----
-// SyntaxError: (90-103): No visibility specified.
+// SyntaxError: (90-103): No visibility specified. Did you intend to add "external"?
// TypeError: (90-103): Fallback function must be defined as "external".
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol
index ec7c0937..73a74219 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/567_require_visibility_specifiers_v050.sol
@@ -3,4 +3,4 @@ contract C {
function f() pure { }
}
// ----
-// SyntaxError: (47-68): No visibility specified.
+// SyntaxError: (47-68): No visibility specified. Did you intend to add "public"?
diff --git a/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol b/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol
index 63800381..4fc7900f 100644
--- a/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol
+++ b/test/libsolidity/syntaxTests/visibility/function_no_visibility.sol
@@ -2,4 +2,4 @@ contract C {
function f() pure { }
}
// ----
-// SyntaxError: (17-38): No visibility specified.
+// SyntaxError: (17-38): No visibility specified. Did you intend to add "public"?
diff --git a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
index 791ba87e..b7e96e5e 100644
--- a/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
+++ b/test/libsolidity/syntaxTests/visibility/interface/function_default.sol
@@ -2,5 +2,5 @@ interface I {
function f();
}
// ----
-// SyntaxError: (15-28): No visibility specified. Did you intend to add "public"?
+// SyntaxError: (15-28): No visibility specified. Did you intend to add "external"?
// TypeError: (15-28): Functions in interfaces must be declared external.
diff --git a/test/libsolidity/syntaxTests/visibility/interface/interface_contract_function_default.sol b/test/libsolidity/syntaxTests/visibility/interface/interface_contract_function_default.sol
new file mode 100644
index 00000000..5d72376f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/visibility/interface/interface_contract_function_default.sol
@@ -0,0 +1,10 @@
+interface I {
+ function f();
+}
+contract C {
+ function g();
+}
+// ----
+// SyntaxError: (18-31): No visibility specified. Did you intend to add "external"?
+// SyntaxError: (51-64): No visibility specified. Did you intend to add "public"?
+// TypeError: (18-31): Functions in interfaces must be declared external.