diff options
author | chriseth <c@ethdev.com> | 2016-11-11 19:07:30 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-11-16 21:37:18 +0800 |
commit | 22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3 (patch) | |
tree | d1214fc92f986a2e973f126be4f2e88576631ef2 /libsolidity/analysis | |
parent | f3d0433ec3aca99f6d9212da944c6fc51cb9292a (diff) | |
download | dexon-solidity-22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3.tar.gz dexon-solidity-22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3.tar.zst dexon-solidity-22b4d1b29a17c6a6360d6d6e42860bd621a7bfd3.zip |
Check that no internals are used in any external function type.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ReferencesResolver.cpp | 9 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 8 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 1 |
3 files changed, 17 insertions, 1 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index c49af013..a0768a34 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -96,7 +96,14 @@ void ReferencesResolver::endVisit(FunctionTypeName const& _typeName) } if (_typeName.isPayable() && _typeName.visibility() != VariableDeclaration::Visibility::External) - fatalTypeError(_typeName.location(), "Only external function types can be payable."); + fatalTypeError(_typeName.location(), "Only external function types can be payable."); + if (_typeName.visibility() == VariableDeclaration::Visibility::External) + for (auto const& t: _typeName.parameterTypes() + _typeName.returnParameterTypes()) + { + solAssert(t->annotation().type, "Type not set for parameter."); + if (!t->annotation().type->canBeUsedExternally(false)) + fatalTypeError(t->location(), "Internal type cannot be used for external function type."); + } _typeName.annotation().type = make_shared<FunctionType>(_typeName); } diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index f934b2c8..8b6d45e2 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -574,6 +574,14 @@ bool TypeChecker::visit(EventDefinition const& _eventDef) return false; } +void TypeChecker::endVisit(FunctionTypeName const& _funType) +{ + FunctionType const& fun = dynamic_cast<FunctionType const&>(*_funType.annotation().type); + if (fun.location() == FunctionType::Location::External) + if (!fun.canBeUsedExternally(false)) + typeError(_funType.location(), "External function type uses internal types."); +} + bool TypeChecker::visit(InlineAssembly const& _inlineAssembly) { // Inline assembly does not have its own type-checking phase, so we just run the diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index be1e02be..5874bb50 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -87,6 +87,7 @@ private: /// case this is a base constructor call. void visitManually(ModifierInvocation const& _modifier, std::vector<ContractDefinition const*> const& _bases); virtual bool visit(EventDefinition const& _eventDef) override; + virtual void endVisit(FunctionTypeName const& _funType) override; virtual bool visit(InlineAssembly const& _inlineAssembly) override; virtual bool visit(IfStatement const& _ifStatement) override; virtual bool visit(WhileStatement const& _whileStatement) override; |