Don't permit close of receive-only channel.

Better panic on attempt to close nil channel.

From-SVN: r180437
This commit is contained in:
Ian Lance Taylor 2011-10-25 16:35:24 +00:00
parent 0d53e34681
commit 09367c0d60
2 changed files with 5 additions and 0 deletions

View File

@ -8153,6 +8153,8 @@ Builtin_call_expression::do_check_types(Gogo*)
{
if (this->one_arg()->type()->channel_type() == NULL)
this->report_error(_("argument must be channel"));
else if (!this->one_arg()->type()->channel_type()->may_send())
this->report_error(_("cannot close receive-only channel"));
}
break;

View File

@ -16,6 +16,9 @@ __go_builtin_close (struct __go_channel *channel)
{
int i;
if (channel == NULL)
__go_panic_msg ("close of nil channel");
i = pthread_mutex_lock (&channel->lock);
__go_assert (i == 0);