Skip to content

Commit

Permalink
compiler: Issue channel type errors earlier.
Browse files Browse the repository at this point in the history
When asking for the type of a receive operation, the compiler would
return an error type if the receive operator was being used on an
invalid channel type and the error would be reported in a later pass.
There are several ways that the type checking pass would not see
the original node and fail to issue the error.  This patch modifies
receive operations to give an error immediately once it is known that
the channel type is invalid.

Fixes golang/go#12323.

Change-Id: Ie3d9c33cf36fd05f49ed807ee52faaeb7d7cfdc2
Reviewed-on: https://go-review.googlesource.com/13987
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
Chris Manghane authored and ianlancetaylor committed Sep 17, 2015
1 parent 1cb26dc commit e069d44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion go/expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13502,9 +13502,14 @@ Expression::make_heap_expression(Expression* expr, Location location)
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();
}

Expand All @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion go/statements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3856,7 +3856,10 @@ Switch_statement::do_lower(Gogo*, Named_object*, Block* enclosing,
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
Expand Down

0 comments on commit e069d44

Please sign in to comment.