compiler: Permit a general expression in case x := <-c.

From-SVN: r183802
This commit is contained in:
Ian Lance Taylor 2012-02-01 14:29:28 +00:00
parent c2453253e7
commit f4f3b9d396

View File

@ -4640,9 +4640,14 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
if (token->is_op(OPERATOR_COLONEQ))
{
// case rv := <-c:
if (!this->advance_token()->is_op(OPERATOR_CHANOP))
this->advance_token();
Expression* e = this->expression(PRECEDENCE_NORMAL, false, false,
NULL);
Receive_expression* re = e->receive_expression();
if (re == NULL)
{
error_at(this->location(), "expected %<<-%>");
if (!e->is_error_expression())
error_at(this->location(), "expected receive expression");
return false;
}
if (recv_var == "_")
@ -4653,8 +4658,7 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
}
*is_send = false;
*varname = gogo->pack_hidden_name(recv_var, is_rv_exported);
this->advance_token();
*channel = this->expression(PRECEDENCE_NORMAL, false, true, NULL);
*channel = re->channel();
return true;
}
else if (token->is_op(OPERATOR_COMMA))
@ -4671,9 +4675,15 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
if (token->is_op(OPERATOR_COLONEQ))
{
// case rv, rc := <-c:
if (!this->advance_token()->is_op(OPERATOR_CHANOP))
this->advance_token();
Expression* e = this->expression(PRECEDENCE_NORMAL, false,
false, NULL);
Receive_expression* re = e->receive_expression();
if (re == NULL)
{
error_at(this->location(), "expected %<<-%>");
if (!e->is_error_expression())
error_at(this->location(),
"expected receive expression");
return false;
}
if (recv_var == "_" && recv_closed == "_")
@ -4689,9 +4699,7 @@ Parse::send_or_recv_stmt(bool* is_send, Expression** channel, Expression** val,
if (recv_closed != "_")
*closedname = gogo->pack_hidden_name(recv_closed,
is_rc_exported);
this->advance_token();
*channel = this->expression(PRECEDENCE_NORMAL, false, true,
NULL);
*channel = re->channel();
return true;
}