mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow overriding external functions in interfaces with public in an implementing contract
This commit is contained in:
parent
ba209fe485
commit
ef3595b000
@ -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.
|
||||||
|
@ -366,6 +366,16 @@ void TypeChecker::checkContractIllegalOverrides(ContractDefinition const& _contr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool functionIsInInterface(FunctionDefinition const& _function)
|
||||||
|
{
|
||||||
|
return dynamic_cast<ContractDefinition const*>(_function.scope()) &&
|
||||||
|
dynamic_cast<ContractDefinition const*>(_function.scope())->contractKind() == ContractDefinition::ContractKind::Interface;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, FunctionDefinition const& super)
|
void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, FunctionDefinition const& super)
|
||||||
{
|
{
|
||||||
FunctionType functionType(function);
|
FunctionType functionType(function);
|
||||||
@ -378,7 +388,12 @@ 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 (functionIsInInterface(super) && !functionIsInInterface(function) && 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(
|
||||||
|
@ -6784,6 +6784,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"(
|
||||||
|
Loading…
Reference in New Issue
Block a user