Treat IndexExpression's type field similar to a FieldExpression.
Treat IndexExpression's type field similar to a FieldExpression.
1.1 --- a/src/BytecodeCompiler.cpp Sat Aug 04 21:06:47 2012 -0700
1.2 +++ b/src/BytecodeCompiler.cpp Sat Aug 04 21:23:39 2012 -0700
1.3 @@ -238,7 +238,6 @@
1.4 __ dup();
1.5 __ getfield(expr->fieldIndex(), expr->type());
1.6 }
1.7 -
1.8 } else {
1.9 IndexExpression *index = node->lvalue()->toIndexExpression();
1.10 __ note_position(index->pos());
1.11 @@ -295,7 +294,7 @@
1.12 // :TODO: get rid of the BOUNDS instruction, embed it in g/setarray*?
1.13 // We can't emit it here because the stack is slightly out of position.
1.14 // __ bounds();
1.15 - __ setarray(index->left()->type()->contained());
1.16 + __ setarray(index->left()->type());
1.17 }
1.18 }
1.19
2.1 --- a/src/SemanticAnalysis.cpp Sat Aug 04 21:06:47 2012 -0700
2.2 +++ b/src/SemanticAnalysis.cpp Sat Aug 04 21:23:39 2012 -0700
2.3 @@ -264,9 +264,6 @@
2.4
2.5 if (type->isReference()) {
2.6 expression->setType(type->contained());
2.7 - } else if (expression->isIndexExpression()) {
2.8 - if (type->isArray())
2.9 - expression->setType(type->contained());
2.10 } else if (expression->isCallExpression()) {
2.11 if (type->isVoid()) {
2.12 CallExpression *call = expression->toCallExpression();
2.13 @@ -275,10 +272,6 @@
2.14 }
2.15 }
2.16
2.17 - // Note that unlike IndexExpression, FieldExpression uses its actual
2.18 - // result type, rather than its parent array type, which can be recovered
2.19 - // from its left-hand side expression.
2.20 -
2.21 return expression->type();
2.22 }
2.23
2.24 @@ -391,7 +384,7 @@
2.25 return NULL;
2.26 }
2.27
2.28 - return type->contained();
2.29 + return type;
2.30 }
2.31
2.32 if (expression->isFieldExpression()) {
2.33 @@ -1126,12 +1119,6 @@
2.34 return;
2.35 }
2.36
2.37 - // If it's an IndexExpression, we special case the ability to compute
2.38 - // a reference.
2.39 - if (expression->isIndexExpression())
2.40 - given = given->contained();
2.41 - assert(!expression->isFieldExpression());
2.42 -
2.43 bool mustComputeReference;
2.44 if (i >= type->parameters()->length()) {
2.45 // Special handling for natives. Arguments past the formal must
2.46 @@ -1210,7 +1197,7 @@
2.47 cc_.reportError(node->left()->pos(), Message_IndexBaseMustBeArray);
2.48 return;
2.49 }
2.50 - node->setType(left);
2.51 + node->setType(left->contained());
2.52 }
2.53
2.54 void