Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
authormjsousa
Sun, 13 Jul 2014 13:47:16 +0100
changeset 910 a0518971127d
parent 909 8b2a31dea131
child 911 ef3347dbfa0c
Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
stage3/narrow_candidate_datatypes.cc
--- a/stage3/narrow_candidate_datatypes.cc	Sun Jul 13 12:26:58 2014 +0100
+++ b/stage3/narrow_candidate_datatypes.cc	Sun Jul 13 13:47:16 2014 +0100
@@ -1382,8 +1382,8 @@
 void *narrow_candidate_datatypes_c::visit(  ref_expression_c  *symbol) {
   if (symbol->exp->candidate_datatypes.size() > 0) {
     symbol->exp->datatype = symbol->exp->candidate_datatypes[0]; /* just use the first possible datatype */
-    symbol->exp->accept(*this);
   }
+  symbol->exp->accept(*this);
   return NULL;
 }
 
@@ -1498,12 +1498,13 @@
 /*********************************/
 
 void *narrow_candidate_datatypes_c::visit(assignment_statement_c *symbol) {
-	if (symbol->candidate_datatypes.size() != 1)
-		return NULL;
-	symbol->datatype = symbol->candidate_datatypes[0];
-	symbol->l_exp->datatype = symbol->datatype;
+	if (symbol->candidate_datatypes.size() == 1) {
+		symbol->datatype = symbol->candidate_datatypes[0];
+		symbol->l_exp->datatype = symbol->datatype;
+		symbol->r_exp->datatype = symbol->datatype;
+	}
+	/* give the chance of any expressions inside array subscripts to be narrowed correctly */
 	symbol->l_exp->accept(*this);
-	symbol->r_exp->datatype = symbol->datatype;
 	symbol->r_exp->accept(*this);
 	return NULL;
 }