aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/AST.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-09-08 22:48:33 +0800
committerchriseth <c@ethdev.com>2015-09-11 21:21:37 +0800
commit337fde9d11adac85800b405a3fdb4bcd09039ebf (patch)
treea0b63ce5ebcb77f26c724a88ef8ce13fbe852879 /libsolidity/AST.cpp
parentc5b6d9d2a9fb379e35435726046ce6c551d25c17 (diff)
downloaddexon-solidity-337fde9d11adac85800b405a3fdb4bcd09039ebf.tar.gz
dexon-solidity-337fde9d11adac85800b405a3fdb4bcd09039ebf.tar.zst
dexon-solidity-337fde9d11adac85800b405a3fdb4bcd09039ebf.zip
Parsing and type checking of libraries without inheritance.
Diffstat (limited to 'libsolidity/AST.cpp')
-rw-r--r--libsolidity/AST.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp
index 1b22c44f..5e51d222 100644
--- a/libsolidity/AST.cpp
+++ b/libsolidity/AST.cpp
@@ -103,6 +103,9 @@ void ContractDefinition::checkTypeRequirements()
));
hashes.insert(hash);
}
+
+ if (isLibrary())
+ checkLibraryRequirements();
}
map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const
@@ -332,6 +335,17 @@ void ContractDefinition::checkExternalTypeClashes() const
));
}
+void ContractDefinition::checkLibraryRequirements() const
+{
+ solAssert(m_isLibrary, "");
+ if (!m_baseContracts.empty())
+ BOOST_THROW_EXCEPTION(createTypeError("Library is not allowed to inherit."));
+
+ for (auto const& var: m_stateVariables)
+ if (!var->isConstant())
+ BOOST_THROW_EXCEPTION(var->createTypeError("Library cannot have non-constant state variables"));
+}
+
vector<ASTPointer<EventDefinition>> const& ContractDefinition::interfaceEvents() const
{
if (!m_interfaceEvents)
@@ -449,6 +463,10 @@ void InheritanceSpecifier::checkTypeRequirements()
ContractDefinition const* base = dynamic_cast<ContractDefinition const*>(&m_baseName->referencedDeclaration());
solAssert(base, "Base contract not available.");
+
+ if (base->isLibrary())
+ BOOST_THROW_EXCEPTION(createTypeError("Libraries cannot be inherited from."));
+
TypePointers parameterTypes = ContractType(*base).constructorType()->parameterTypes();
if (!m_arguments.empty() && parameterTypes.size() != m_arguments.size())
BOOST_THROW_EXCEPTION(createTypeError(