From be15e0b424d9a7bd181c8525dbb2eb0a26806c13 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 21 Feb 2015 00:46:35 +0100 Subject: [PATCH] Index access. --- AST.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/AST.cpp b/AST.cpp index a18785ae1..4e4fe7d5b 100644 --- a/AST.cpp +++ b/AST.cpp @@ -609,13 +609,28 @@ void MemberAccess::checkTypeRequirements() void IndexAccess::checkTypeRequirements() { m_base->checkTypeRequirements(); - if (m_base->getType()->getCategory() != Type::Category::Mapping) - BOOST_THROW_EXCEPTION(m_base->createTypeError("Indexed expression has to be a mapping (is " + - m_base->getType()->toString() + ")")); - MappingType const& type = dynamic_cast(*m_base->getType()); - m_index->expectType(*type.getKeyType()); - m_type = type.getValueType(); - m_isLValue = true; + switch (m_base->getType()->getCategory()) + { + case Type::Category::Array: + { + ArrayType const& type = dynamic_cast(*m_base->getType()); + m_index->expectType(IntegerType(256)); + m_type = type.getBaseType(); + m_isLValue = true; + break; + } + case Type::Category::Mapping: + { + MappingType const& type = dynamic_cast(*m_base->getType()); + m_index->expectType(*type.getKeyType()); + m_type = type.getValueType(); + m_isLValue = true; + break; + } + default: + BOOST_THROW_EXCEPTION(m_base->createTypeError( + "Indexed expression has to be a mapping or array (is " + m_base->getType()->toString() + ")")); + } } void Identifier::checkTypeRequirements()