Commit 09367c0d by Ian Lance Taylor

Don't permit close of receive-only channel.

Better panic on attempt to close nil channel.

From-SVN: r180437
parent 0d53e346
...@@ -8153,6 +8153,8 @@ Builtin_call_expression::do_check_types(Gogo*) ...@@ -8153,6 +8153,8 @@ Builtin_call_expression::do_check_types(Gogo*)
{ {
if (this->one_arg()->type()->channel_type() == NULL) if (this->one_arg()->type()->channel_type() == NULL)
this->report_error(_("argument must be channel")); 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; break;
......
...@@ -16,6 +16,9 @@ __go_builtin_close (struct __go_channel *channel) ...@@ -16,6 +16,9 @@ __go_builtin_close (struct __go_channel *channel)
{ {
int i; int i;
if (channel == NULL)
__go_panic_msg ("close of nil channel");
i = pthread_mutex_lock (&channel->lock); i = pthread_mutex_lock (&channel->lock);
__go_assert (i == 0); __go_assert (i == 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment