Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force interface functions as external (0.5.0) #3038

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Features:
* Syntax Checker: Unary ``+`` is now a syntax error as experimental 0.5.0 feature.
* Type Checker: Disallow non-pure constant state variables as experimental 0.5.0 feature.
* Type Checker: Do not add members of ``address`` to contracts as experimental 0.5.0 feature.
* Type Checker: Force interface functions to be external as experimental 0.5.0 feature.
* Type Checker: Require ``storage`` or ``memory`` keyword for local variables as experimental 0.5.0 feature.

Bugfixes:
Expand Down
12 changes: 10 additions & 2 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,16 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
{
if (_function.isImplemented())
m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot have an implementation.");
if (_function.visibility() < FunctionDefinition::Visibility::Public)
m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot be internal or private.");
if (_function.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
{
if (_function.visibility() != FunctionDefinition::Visibility::External)
m_errorReporter.typeError(_function.location(), "Functions in interfaces must be declared external.");
}
else
{
if (_function.visibility() < FunctionDefinition::Visibility::Public)
m_errorReporter.typeError(_function.location(), "Functions in interfaces cannot be internal or private.");
}
if (_function.isConstructor())
m_errorReporter.typeError(_function.location(), "Constructor cannot be defined in interfaces.");
}
Expand Down
22 changes: 22 additions & 0 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5879,6 +5879,28 @@ BOOST_AUTO_TEST_CASE(interface_function_bodies)
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;
}
)";
success(text);
}

BOOST_AUTO_TEST_CASE(interface_function_public)
{
char const* 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"(
Expand Down