This patch by Chris Manghane changes the Go frontend to issue type errors earlier for a receive operation. This fixes https://golang.org/issue/12323 . Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 227834) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -1cb26dc898bda1e85f4dd2ee204adbce792e4813 +e069d4417a692c1261df99fe3323277e1a0193d2 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 227834) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -13502,9 +13502,14 @@ Expression::make_heap_expression(Express Type* Receive_expression::do_type() { + if (this->is_error_expression()) + return Type::make_error_type(); Channel_type* channel_type = this->channel_->type()->channel_type(); if (channel_type == NULL) - return Type::make_error_type(); + { + this->report_error(_("expected channel")); + return Type::make_error_type(); + } return channel_type->element_type(); } @@ -13516,6 +13521,7 @@ Receive_expression::do_check_types(Gogo* Type* type = this->channel_->type(); if (type->is_error()) { + go_assert(saw_errors()); this->set_is_error(); return; } Index: gcc/go/gofrontend/statements.cc =================================================================== --- gcc/go/gofrontend/statements.cc (revision 227696) +++ gcc/go/gofrontend/statements.cc (working copy) @@ -3856,7 +3856,10 @@ Switch_statement::do_lower(Gogo*, Named_ if (this->val_ != NULL && (this->val_->is_error_expression() || this->val_->type()->is_error())) - return Statement::make_error_statement(loc); + { + go_assert(saw_errors()); + return Statement::make_error_statement(loc); + } if (this->val_ != NULL && this->val_->type()->integer_type() != NULL