Merge pull request #3681 from ethereum/interface-external

Allow overriding external functions in interfaces with public in a child
This commit is contained in:
chriseth 2018-03-27 15:47:59 +02:00 committed by GitHub
commit 62559cf127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 0 deletions

View File

@ -2,6 +2,7 @@
Features: Features:
* General: Support accessing dynamic return data in post-byzantium EVMs. * General: Support accessing dynamic return data in post-byzantium EVMs.
* Interfaces: Allow overriding external functions in interfaces with public in an implementing contract.
Bugfixes: Bugfixes:
* Code Generator: Allow ``block.blockhash`` without being called. * Code Generator: Allow ``block.blockhash`` without being called.

View File

@ -378,7 +378,16 @@ void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, Func
function.annotation().superFunction = &super; function.annotation().superFunction = &super;
if (function.visibility() != super.visibility()) if (function.visibility() != super.visibility())
{
// visibility is enforced to be external in interfaces, but a contract can override that with public
if (
super.inContractKind() == ContractDefinition::ContractKind::Interface &&
function.inContractKind() != ContractDefinition::ContractKind::Interface &&
function.visibility() == FunctionDefinition::Visibility::Public
)
return;
overrideError(function, super, "Overriding function visibility differs."); overrideError(function, super, "Overriding function visibility differs.");
}
else if (function.stateMutability() != super.stateMutability()) else if (function.stateMutability() != super.stateMutability())
overrideError( overrideError(

View File

@ -290,6 +290,13 @@ TypeDeclarationAnnotation& EnumDefinition::annotation() const
return dynamic_cast<TypeDeclarationAnnotation&>(*m_annotation); return dynamic_cast<TypeDeclarationAnnotation&>(*m_annotation);
} }
ContractDefinition::ContractKind FunctionDefinition::inContractKind() const
{
auto contractDef = dynamic_cast<ContractDefinition const*>(scope());
solAssert(contractDef, "Enclosing Scope of FunctionDefinition was not set.");
return contractDef->contractKind();
}
shared_ptr<FunctionType> FunctionDefinition::functionType(bool _internal) const shared_ptr<FunctionType> FunctionDefinition::functionType(bool _internal) const
{ {
if (_internal) if (_internal)

View File

@ -624,6 +624,8 @@ public:
/// arguments separated by commas all enclosed in parentheses without any spaces. /// arguments separated by commas all enclosed in parentheses without any spaces.
std::string externalSignature() const; std::string externalSignature() const;
ContractDefinition::ContractKind inContractKind() const;
virtual TypePointer type() const override; virtual TypePointer type() const override;
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned. /// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.

View File

@ -6561,6 +6561,20 @@ BOOST_AUTO_TEST_CASE(using_interface_complex)
CHECK_SUCCESS(text); CHECK_SUCCESS(text);
} }
BOOST_AUTO_TEST_CASE(interface_implement_public_contract)
{
char const* text = R"(
interface I {
function f() external;
}
contract C is I {
function f() public {
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(warn_about_throw) BOOST_AUTO_TEST_CASE(warn_about_throw)
{ {
char const* text = R"( char const* text = R"(