Commit ea9e9386 authored by Luuk van Dijk's avatar Luuk van Dijk

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

Fixes #2354

R=rsc
CC=golang-dev
https://golang.org/cl/5346044
parent 0d6f857c
...@@ -46,6 +46,10 @@ typecheckrange(Node *n) ...@@ -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)
......
...@@ -48,7 +48,10 @@ func main() { ...@@ -48,7 +48,10 @@ func main() {
case x := <-cs: // ERROR "receive" case x := <-cs: // ERROR "receive"
_ = x _ = x
} }
for _ = range cs {// ERROR "receive"
}
close(c) close(c)
close(cs) close(cs)
close(cr) // ERROR "receive" close(cr) // ERROR "receive"
......
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