diff options
author | chriseth <c@ethdev.com> | 2015-04-16 06:06:57 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2015-04-16 06:09:28 +0800 |
commit | 6e5de4832da7a3c2fdbc87b71523ac671083d9c0 (patch) | |
tree | 6bd30af9e9ccf2130cdb2ecad40466f0f88bdce7 | |
parent | 820239a73c08ceb359e5d7dda9162b7e2f0fcaed (diff) | |
download | dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.tar dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.tar.gz dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.tar.bz2 dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.tar.lz dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.tar.xz dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.tar.zst dexon-solidity-6e5de4832da7a3c2fdbc87b71523ac671083d9c0.zip |
Bugfixes concerning variable declarations.
Fixes #1637
-rw-r--r-- | AST.cpp | 16 | ||||
-rw-r--r-- | Parser.cpp | 23 |
2 files changed, 19 insertions, 20 deletions
@@ -378,20 +378,16 @@ void VariableDeclaration::checkTypeRequirements() if ((m_type && !m_type->isValueType()) || !m_value) BOOST_THROW_EXCEPTION(createTypeError("Unitialized \"constant\" variable.")); } - if (!m_value) - return; if (m_type) { - m_value->expectType(*m_type); - if (m_isStateVariable && !m_type->externalType() && getVisibility() >= Visibility::Public) - BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for state variables.")); - - if (!FunctionType(*this).externalType()) - BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for public state variables.")); + if (m_value) + m_value->expectType(*m_type); } else { - // no type declared and no previous assignment, infer the type + if (!m_value) + // This feature might be extended in the future. + BOOST_THROW_EXCEPTION(createTypeError("Assignment necessary for type detection.")); m_value->checkTypeRequirements(); TypePointer type = m_value->getType(); if (type->getCategory() == Type::Category::IntegerConstant) @@ -405,6 +401,8 @@ void VariableDeclaration::checkTypeRequirements() BOOST_THROW_EXCEPTION(createTypeError("Variable cannot have void type.")); m_type = type; } + if (m_isStateVariable && getVisibility() >= Visibility::Public && !FunctionType(*this).externalType()) + BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for public state variables.")); } bool VariableDeclaration::isExternalFunctionParameter() const @@ -472,17 +472,18 @@ ASTPointer<TypeName> Parser::parseTypeName(bool _allowVar) else BOOST_THROW_EXCEPTION(createParserError("Expected type name")); - // Parse "[...]" postfixes for arrays. - while (m_scanner->getCurrentToken() == Token::LBrack) - { - m_scanner->next(); - ASTPointer<Expression> length; - if (m_scanner->getCurrentToken() != Token::RBrack) - length = parseExpression(); - nodeFactory.markEndPosition(); - expectToken(Token::RBrack); - type = nodeFactory.createNode<ArrayTypeName>(type, length); - } + if (type) + // Parse "[...]" postfixes for arrays. + while (m_scanner->getCurrentToken() == Token::LBrack) + { + m_scanner->next(); + ASTPointer<Expression> length; + if (m_scanner->getCurrentToken() != Token::RBrack) + length = parseExpression(); + nodeFactory.markEndPosition(); + expectToken(Token::RBrack); + type = nodeFactory.createNode<ArrayTypeName>(type, length); + } return type; } |