diff options
author | Christian <c@ethdev.com> | 2015-01-20 04:05:47 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-01-20 06:35:04 +0800 |
commit | af92f98d86ba1e15e3f41ac49bb9639be1ab4e41 (patch) | |
tree | e42cff46c9701491a43e58bebd8ead5b3e5241ec /AST.cpp | |
parent | 6e111d5d1da2a0ae397fa2bd846d13132cdd6dd9 (diff) | |
download | dexon-solidity-af92f98d86ba1e15e3f41ac49bb9639be1ab4e41.tar.gz dexon-solidity-af92f98d86ba1e15e3f41ac49bb9639be1ab4e41.tar.zst dexon-solidity-af92f98d86ba1e15e3f41ac49bb9639be1ab4e41.zip |
Constructor arguments for base classes.
Diffstat (limited to 'AST.cpp')
-rw-r--r-- | AST.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -43,6 +43,9 @@ TypeError ASTNode::createTypeError(string const& _description) const void ContractDefinition::checkTypeRequirements() { + for (ASTPointer<InheritanceSpecifier> const& base: getBaseContracts()) + base->checkTypeRequirements(); + checkIllegalOverrides(); FunctionDefinition const* constructor = getConstructor(); @@ -123,6 +126,22 @@ vector<pair<FixedHash<4>, FunctionDefinition const*>> const& ContractDefinition: return *m_interfaceFunctionList; } +void InheritanceSpecifier::checkTypeRequirements() +{ + m_baseName->checkTypeRequirements(); + for (ASTPointer<Expression> const& argument: m_arguments) + argument->checkTypeRequirements(); + + ContractDefinition const* base = dynamic_cast<ContractDefinition const*>(m_baseName->getReferencedDeclaration()); + solAssert(base, "Base contract not available."); + TypePointers parameterTypes = ContractType(*base).getConstructorType()->getParameterTypes(); + if (parameterTypes.size() != m_arguments.size()) + BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for constructor call.")); + for (size_t i = 0; i < m_arguments.size(); ++i) + if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i])) + BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in constructer call.")); +} + void StructDefinition::checkMemberTypes() const { for (ASTPointer<VariableDeclaration> const& member: getMembers()) |