The Go language was changed slightly to prohibit calling close on a receive-only channel. This patch changes the Go frontend accordingly. This patch also implements a better panic for an attempt to close a nil channel. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r 4dea0e134ef6 go/expressions.cc --- a/go/expressions.cc Mon Oct 24 22:36:05 2011 -0700 +++ b/go/expressions.cc Tue Oct 25 09:07:49 2011 -0700 @@ -8153,6 +8153,8 @@ { 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; diff -r 4dea0e134ef6 libgo/runtime/go-close.c --- a/libgo/runtime/go-close.c Mon Oct 24 22:36:05 2011 -0700 +++ b/libgo/runtime/go-close.c Tue Oct 25 09:07:49 2011 -0700 @@ -16,6 +16,9 @@ { int i; + if (channel == NULL) + __go_panic_msg ("close of nil channel"); + i = pthread_mutex_lock (&channel->lock); __go_assert (i == 0);