]> Cypherpunks repositories - gostls13.git/commitdiff
gc: Better error message for range over non-receive channel.
authorLuuk van Dijk <lvd@golang.org>
Sun, 6 Nov 2011 21:14:15 +0000 (22:14 +0100)
committerLuuk van Dijk <lvd@golang.org>
Sun, 6 Nov 2011 21:14:15 +0000 (22:14 +0100)
Fixes #2354

R=rsc
CC=golang-dev
https://golang.org/cl/5346044

src/cmd/gc/range.c
test/chan/perm.go

index 1909c9ec778aba59665734e3a302ff921359712a..25d1131ec3dab2631ec0746fa203ca666dbd342b 100644 (file)
@@ -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)
index af054450eabafbe67bc3f317e9d9b98afe567666..a43df198214b21d5b8dfa16e764e1a8435f4767f 100644 (file)
@@ -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"