aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuuk van Dijk <lvd@golang.org>2011-11-06 22:14:15 +0100
committerLuuk van Dijk <lvd@golang.org>2011-11-06 22:14:15 +0100
commitea9e93862d9b6fc0c5b53cdb204204923d653b8a (patch)
tree76d51919b8499118eca4bf49e197e87aa05ee5aa
parent0d6f857c3f76b9285ab2866e8715e333a3429449 (diff)
downloadgo-ea9e93862d9b6fc0c5b53cdb204204923d653b8a.tar.gz
go-ea9e93862d9b6fc0c5b53cdb204204923d653b8a.zip
gc: Better error message for range over non-receive channel.
Fixes #2354 R=rsc CC=golang-dev https://golang.org/cl/5346044
-rw-r--r--src/cmd/gc/range.c4
-rw-r--r--test/chan/perm.go5
2 files changed, 8 insertions, 1 deletions
diff --git a/src/cmd/gc/range.c b/src/cmd/gc/range.c
index 1909c9ec77..25d1131ec3 100644
--- a/src/cmd/gc/range.c
+++ b/src/cmd/gc/range.c
@@ -46,6 +46,10 @@ typecheckrange(Node *n)
break;
case TCHAN:
+ if(!(t->chan & Crecv)) {
+ yyerror("invalid operation: range %N (receive from send-only type %T)", n->right, n->right->type);
+ goto out;
+ }
t1 = t->type;
t2 = nil;
if(count(n->list) == 2)
diff --git a/test/chan/perm.go b/test/chan/perm.go
index af054450ea..a43df19821 100644
--- a/test/chan/perm.go
+++ b/test/chan/perm.go
@@ -48,7 +48,10 @@ func main() {
case x := <-cs: // ERROR "receive"
_ = x
}
-
+
+ for _ = range cs {// ERROR "receive"
+ }
+
close(c)
close(cs)
close(cr) // ERROR "receive"