mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3681 from ethereum/interface-external
Allow overriding external functions in interfaces with public in a child
This commit is contained in:
commit
62559cf127
@ -2,6 +2,7 @@
|
||||
|
||||
Features:
|
||||
* General: Support accessing dynamic return data in post-byzantium EVMs.
|
||||
* Interfaces: Allow overriding external functions in interfaces with public in an implementing contract.
|
||||
|
||||
Bugfixes:
|
||||
* Code Generator: Allow ``block.blockhash`` without being called.
|
||||
|
@ -378,7 +378,16 @@ void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, Func
|
||||
function.annotation().superFunction = &super;
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
else if (function.stateMutability() != super.stateMutability())
|
||||
overrideError(
|
||||
|
@ -290,6 +290,13 @@ TypeDeclarationAnnotation& EnumDefinition::annotation() const
|
||||
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
|
||||
{
|
||||
if (_internal)
|
||||
|
@ -624,6 +624,8 @@ public:
|
||||
/// arguments separated by commas all enclosed in parentheses without any spaces.
|
||||
std::string externalSignature() const;
|
||||
|
||||
ContractDefinition::ContractKind inContractKind() const;
|
||||
|
||||
virtual TypePointer type() const override;
|
||||
|
||||
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.
|
||||
|
@ -6561,6 +6561,20 @@ BOOST_AUTO_TEST_CASE(using_interface_complex)
|
||||
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)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user