diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-02-08 06:13:03 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-03-18 00:27:04 +0800 |
commit | 4693aed17744810387c887194f07ba1a969b0a05 (patch) | |
tree | 40ce68202716e9cee88d30098f78aa6705aa3689 /libsolidity/analysis | |
parent | 54230d2d5d15638fdf7c3893ee436fd8bc380e8c (diff) | |
download | dexon-solidity-4693aed17744810387c887194f07ba1a969b0a05.tar.gz dexon-solidity-4693aed17744810387c887194f07ba1a969b0a05.tar.zst dexon-solidity-4693aed17744810387c887194f07ba1a969b0a05.zip |
Reject invalid definitions for interface contracts
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 34ed8129..889b72b9 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -354,6 +354,9 @@ void TypeChecker::endVisit(InheritanceSpecifier const& _inheritance) auto base = dynamic_cast<ContractDefinition const*>(&dereference(_inheritance.name())); solAssert(base, "Base contract not available."); + if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface) + typeError(_inheritance.location(), "Interfaces cannot inherit."); + if (base->isLibrary()) typeError(_inheritance.location(), "Libraries cannot be inherited from."); @@ -396,6 +399,9 @@ void TypeChecker::endVisit(UsingForDirective const& _usingFor) bool TypeChecker::visit(StructDefinition const& _struct) { + if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface) + typeError(_struct.location(), "Structs cannot be defined in interfaces."); + for (ASTPointer<VariableDeclaration> const& member: _struct.members()) if (!type(*member)->canBeStored()) typeError(member->location(), "Type cannot be used in struct."); @@ -452,12 +458,19 @@ bool TypeChecker::visit(FunctionDefinition const& _function) vector<ContractDefinition const*>() ); if (_function.isImplemented()) + { + if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface) + typeError(_function.location(), "Functions in interfaces cannot have an implementation."); _function.body().accept(*this); + } return false; } bool TypeChecker::visit(VariableDeclaration const& _variable) { + if (m_scope->contractKind() == ContractDefinition::ContractKind::Interface) + typeError(_variable.location(), "Variables cannot be defined in interfaces."); + // Variables can be declared without type (with "var"), in which case the first assignment // sets the type. // Note that assignments before the first declaration are legal because of the special scoping |