This patch by Chris Manghane fixes a bug in the gofrontend in which map index expressions were not treated as lvalues in range expressions. That is, for m[0] = range s did not work. This was Go issue 9695. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r 172f17c15975 go/parse.cc --- a/go/parse.cc Fri Jan 30 08:04:31 2015 -0800 +++ b/go/parse.cc Fri Jan 30 16:17:50 2015 -0800 @@ -4011,36 +4011,8 @@ token = this->advance_token(); - if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE)) - { - if (op != OPERATOR_EQ) - error_at(this->location(), "range clause requires %<=%>"); - this->range_clause_expr(lhs, p_range_clause); - return; - } - - Expression_list* vals = this->expression_list(NULL, false, - may_be_composite_lit); - - // We've parsed everything; check for errors. - if (lhs == NULL || vals == NULL) + if (lhs == NULL) return; - for (Expression_list::const_iterator pe = lhs->begin(); - pe != lhs->end(); - ++pe) - { - if ((*pe)->is_error_expression()) - return; - if (op != OPERATOR_EQ && (*pe)->is_sink_expression()) - error_at((*pe)->location(), "cannot use _ as value"); - } - for (Expression_list::const_iterator pe = vals->begin(); - pe != vals->end(); - ++pe) - { - if ((*pe)->is_error_expression()) - return; - } // Map expressions act differently when they are lvalues. for (Expression_list::iterator plv = lhs->begin(); @@ -4049,6 +4021,37 @@ if ((*plv)->index_expression() != NULL) (*plv)->index_expression()->set_is_lvalue(); + if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE)) + { + if (op != OPERATOR_EQ) + error_at(this->location(), "range clause requires %<=%>"); + this->range_clause_expr(lhs, p_range_clause); + return; + } + + Expression_list* vals = this->expression_list(NULL, false, + may_be_composite_lit); + + // We've parsed everything; check for errors. + if (vals == NULL) + return; + for (Expression_list::const_iterator pe = lhs->begin(); + pe != lhs->end(); + ++pe) + { + if ((*pe)->is_error_expression()) + return; + if (op != OPERATOR_EQ && (*pe)->is_sink_expression()) + error_at((*pe)->location(), "cannot use _ as value"); + } + for (Expression_list::const_iterator pe = vals->begin(); + pe != vals->end(); + ++pe) + { + if ((*pe)->is_error_expression()) + return; + } + Call_expression* call; Index_expression* map_index; Receive_expression* receive;