Suggests external for fallback and interface functions.

This commit is contained in:
chriseth 2018-07-10 22:43:02 +02:00 committed by Erik Kundt
parent 75bba5c9f0
commit dfd2fee91d
9 changed files with 31 additions and 7 deletions

View File

@ -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())
{

View File

@ -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;
};

View File

@ -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"?

View File

@ -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"?

View File

@ -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".

View File

@ -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"?

View File

@ -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"?

View File

@ -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.

View File

@ -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.