diff options
author | chriseth <chris@ethereum.org> | 2018-03-27 21:47:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-27 21:47:59 +0800 |
commit | 62559cf1278afc417d19ec181e2bced364cadea2 (patch) | |
tree | 9fdc3e2f01c046ec6a29e8c402f11f72625b2e03 /libsolidity | |
parent | 8c1352ca7562962b46638da17a293c982bc1dba9 (diff) | |
parent | 8bae2dba7c9697d129a43c1dde54690f3e37a84a (diff) | |
download | dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar.gz dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar.bz2 dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar.lz dexon-solidity-62559cf1278afc417d19ec181e2bced364cadea2.tar.xz 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
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 9 | ||||
-rw-r--r-- | libsolidity/ast/AST.cpp | 7 | ||||
-rw-r--r-- | libsolidity/ast/AST.h | 2 |
3 files changed, 18 insertions, 0 deletions
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. |