Merge pull request #3699 from ethereum/interfaceExternalVisibility

Defaults to external visibility for interfaces.
This commit is contained in:
Alex Beregszaszi 2018-04-03 15:15:36 +01:00 committed by GitHub
commit 7753249f64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 52 additions and 60 deletions

View File

@ -50,6 +50,16 @@ void StaticAnalyzer::endVisit(ContractDefinition const&)
bool StaticAnalyzer::visit(FunctionDefinition const& _function) 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()) if (_function.isImplemented())
m_currentFunction = &_function; m_currentFunction = &_function;
else else

View File

@ -214,18 +214,9 @@ bool SyntaxChecker::visit(FunctionDefinition const& _function)
{ {
bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050); bool const v050 = m_sourceUnit->annotation().experimentalFeatures.count(ExperimentalFeature::V050);
if (_function.noVisibilitySpecified()) if (v050 && _function.noVisibilitySpecified())
{ m_errorReporter.syntaxError(_function.location(), "No visibility specified.");
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; return true;
} }

View File

@ -6429,54 +6429,6 @@ BOOST_AUTO_TEST_CASE(interface_function_bodies)
CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation"); CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation");
} }
BOOST_AUTO_TEST_CASE(interface_function_external)
{
char const* text = R"(
pragma experimental "v0.5.0";
interface I {
function f() external;
}
)";
CHECK_SUCCESS(text);
}
BOOST_AUTO_TEST_CASE(interface_function_public)
{
char const* text = R"(
interface I {
function f() public;
}
)";
CHECK_WARNING(text, "Functions in interfaces should be declared external.");
text = R"(
pragma experimental "v0.5.0";
interface I {
function f() public;
}
)";
CHECK_ERROR(text, TypeError, "Functions in interfaces must be declared external.");
}
BOOST_AUTO_TEST_CASE(interface_function_internal)
{
char const* text = R"(
interface I {
function f() internal;
}
)";
CHECK_ERROR(text, TypeError, "Functions in interfaces cannot be internal or private.");
}
BOOST_AUTO_TEST_CASE(interface_function_private)
{
char const* text = R"(
interface I {
function f() private;
}
)";
CHECK_ERROR(text, TypeError, "Functions in interfaces cannot be internal or private.");
}
BOOST_AUTO_TEST_CASE(interface_events) BOOST_AUTO_TEST_CASE(interface_events)
{ {
char const* text = R"( char const* text = R"(

View File

@ -0,0 +1,6 @@
interface I {
function f();
}
// ----
// Warning: Functions in interfaces should be declared external.
// Warning: No visibility specified. Defaulting to "public". In interfaces it defaults to external.

View File

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

View File

@ -0,0 +1,5 @@
pragma experimental "v0.5.0";
interface I {
function f() external;
}
// ----

View File

@ -0,0 +1,5 @@
interface I {
function f() internal;
}
// ----
// TypeError: Functions in interfaces cannot be internal or private.

View File

@ -0,0 +1,5 @@
interface I {
function f() private;
}
// ----
// TypeError: Functions in interfaces cannot be internal or private.

View File

@ -0,0 +1,5 @@
interface I {
function f() public;
}
// ----
// Warning: Functions in interfaces should be declared external.

View File

@ -0,0 +1,6 @@
pragma experimental "v0.5.0";
interface I {
function f() public;
}
// ----
// TypeError: Functions in interfaces must be declared external.