1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:54:40 -07:00

gc: Better error message for range over non-receive channel.

Fixes #2354

R=rsc
CC=golang-dev
https://golang.org/cl/5346044
This commit is contained in:
Luuk van Dijk 2011-11-06 22:14:15 +01:00
parent 0d6f857c3f
commit ea9e93862d
2 changed files with 8 additions and 1 deletions

View File

@ -46,6 +46,10 @@ typecheckrange(Node *n)
break; break;
case TCHAN: 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; t1 = t->type;
t2 = nil; t2 = nil;
if(count(n->list) == 2) if(count(n->list) == 2)

View File

@ -49,6 +49,9 @@ func main() {
_ = x _ = x
} }
for _ = range cs {// ERROR "receive"
}
close(c) close(c)
close(cs) close(cs)
close(cr) // ERROR "receive" close(cr) // ERROR "receive"