diff options
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 16 | ||||
-rw-r--r-- | libsolidity/ast/AST.cpp | 7 | ||||
-rw-r--r-- | libsolidity/ast/AST.h | 2 |
3 files changed, 14 insertions, 11 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 487959c5..6e287f83 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -366,16 +366,6 @@ 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) { FunctionType functionType(function); @@ -390,7 +380,11 @@ void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, Func 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) + if ( + super.inContractKind() == ContractDefinition::ContractKind::Interface && + function.inContractKind() != ContractDefinition::ContractKind::Interface && + function.visibility() == FunctionDefinition::Visibility::Public + ) return; overrideError(function, super, "Overriding function visibility differs."); } 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. |