aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/AST.cpp b/AST.cpp
index 761427db..a18785ae 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -77,6 +77,9 @@ void ContractDefinition::checkTypeRequirements()
for (ASTPointer<FunctionDefinition> const& function: getDefinedFunctions())
function->checkTypeRequirements();
+ for (ASTPointer<VariableDeclaration> const& variable: m_stateVariables)
+ variable->checkTypeRequirements();
+
// check for hash collisions in function signatures
set<FixedHash<4>> hashes;
for (auto const& it: getInterfaceFunctionList())
@@ -294,6 +297,12 @@ bool VariableDeclaration::isLValue() const
return !isExternalFunctionParameter();
}
+void VariableDeclaration::checkTypeRequirements()
+{
+ if (m_value)
+ m_value->checkTypeRequirements();
+}
+
bool VariableDeclaration::isExternalFunctionParameter() const
{
auto const* function = dynamic_cast<FunctionDefinition const*>(getScope());
@@ -390,26 +399,26 @@ void Return::checkTypeRequirements()
m_expression->expectType(*m_returnParameters->getParameters().front()->getType());
}
-void VariableDefinition::checkTypeRequirements()
+void VariableDeclarationStatement::checkTypeRequirements()
{
// 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
// rules inherited from JavaScript.
- if (m_value)
+ if (m_variable->getValue())
{
if (m_variable->getType())
- m_value->expectType(*m_variable->getType());
+ m_variable->getValue()->expectType(*m_variable->getType());
else
{
// no type declared and no previous assignment, infer the type
- m_value->checkTypeRequirements();
- TypePointer type = m_value->getType();
+ m_variable->getValue()->checkTypeRequirements();
+ TypePointer type = m_variable->getValue()->getType();
if (type->getCategory() == Type::Category::IntegerConstant)
{
auto intType = dynamic_pointer_cast<IntegerConstantType const>(type)->getIntegerType();
if (!intType)
- BOOST_THROW_EXCEPTION(m_value->createTypeError("Invalid integer constant " + type->toString()));
+ BOOST_THROW_EXCEPTION(m_variable->getValue()->createTypeError("Invalid integer constant " + type->toString()));
type = intType;
}
else if (type->getCategory() == Type::Category::Void)
@@ -418,7 +427,6 @@ void VariableDefinition::checkTypeRequirements()
}
}
}
-
void Assignment::checkTypeRequirements()
{
m_leftHandSide->checkTypeRequirements();