mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Issue error if no visibility is specified (on 0.5.0)
This commit is contained in:
parent
2abc5be7e6
commit
a566825589
@ -7,6 +7,7 @@ Features:
|
||||
* Support and recommend using ``emit EventName();`` to call events explicitly.
|
||||
* Syntax Analyser: Do not warn about experimental features if they do not concern code generation.
|
||||
* Syntax Checker: Mark ``throw`` as an error as experimental 0.5.0 feature.
|
||||
* Syntax Checker: Issue error if no visibility is specified on contract functions as experimental 0.5.0 feature.
|
||||
|
||||
Bugfixes:
|
||||
* Assembly: Raise error on oversized number literals in assembly.
|
||||
|
@ -212,13 +212,20 @@ bool SyntaxChecker::visit(PlaceholderStatement const&)
|
||||
|
||||
bool SyntaxChecker::visit(FunctionDefinition const& _function)
|
||||
{
|
||||
bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050);
|
||||
|
||||
if (_function.noVisibilitySpecified())
|
||||
m_errorReporter.warning(
|
||||
_function.location(),
|
||||
"No visibility specified. Defaulting to \"" +
|
||||
Declaration::visibilityToString(_function.visibility()) +
|
||||
"\"."
|
||||
);
|
||||
{
|
||||
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()) +
|
||||
"\"."
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7741,7 +7741,7 @@ BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
|
||||
char const* text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() {
|
||||
function f() public {
|
||||
this.balance;
|
||||
}
|
||||
}
|
||||
@ -7750,7 +7750,7 @@ BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
|
||||
text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() {
|
||||
function f() public {
|
||||
this.transfer;
|
||||
}
|
||||
}
|
||||
@ -7759,7 +7759,7 @@ BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
|
||||
text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() {
|
||||
function f() public {
|
||||
this.send;
|
||||
}
|
||||
}
|
||||
@ -7768,7 +7768,7 @@ BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
|
||||
text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() {
|
||||
function f() public {
|
||||
this.call;
|
||||
}
|
||||
}
|
||||
@ -7777,7 +7777,7 @@ BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
|
||||
text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() {
|
||||
function f() public {
|
||||
this.callcode;
|
||||
}
|
||||
}
|
||||
@ -7786,7 +7786,7 @@ BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
|
||||
text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() {
|
||||
function f() public {
|
||||
this.delegatecall;
|
||||
}
|
||||
}
|
||||
@ -7870,6 +7870,23 @@ BOOST_AUTO_TEST_CASE(getter_is_memory_type)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(require_visibility_specifiers)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
function f() pure { }
|
||||
}
|
||||
)";
|
||||
CHECK_WARNING(text, "No visibility specified. Defaulting to");
|
||||
text = R"(
|
||||
pragma experimental "v0.5.0";
|
||||
contract C {
|
||||
function f() pure { }
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, SyntaxError, "No visibility specified.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(environment_access)
|
||||
BOOST_AUTO_TEST_CASE(view_error_for_050)
|
||||
{
|
||||
CHECK_ERROR(
|
||||
"pragma experimental \"v0.5.0\"; contract C { uint x; function f() view { x = 2; } }",
|
||||
"pragma experimental \"v0.5.0\"; contract C { uint x; function f() view public { x = 2; } }",
|
||||
TypeError,
|
||||
"Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable."
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user