aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-03-27 21:47:59 +0800
committerGitHub <noreply@github.com>2018-03-27 21:47:59 +0800
commit62559cf1278afc417d19ec181e2bced364cadea2 (patch)
tree9fdc3e2f01c046ec6a29e8c402f11f72625b2e03
parent8c1352ca7562962b46638da17a293c982bc1dba9 (diff)
parent8bae2dba7c9697d129a43c1dde54690f3e37a84a (diff)
downloaddexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar.gz
dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar.zst
dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.zip
Merge pull request #3681 from ethereum/interface-external
Allow overriding external functions in interfaces with public in a child
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp9
-rw-r--r--libsolidity/ast/AST.cpp7
-rw-r--r--libsolidity/ast/AST.h2
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp14
5 files changed, 33 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index aa1554f5..9235ed3a 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -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.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 999a2a97..6e287f83 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -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(
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp
index 27220b1f..d8ad009d 100644
--- a/libsolidity/ast/AST.cpp
+++ b/libsolidity/ast/AST.cpp
@@ -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)
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index a25df64b..9c67d354 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -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.
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 565168a2..c5abac03 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -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"(