]> Cypherpunks repositories - gostls13.git/commitdiff
restrict declarations of type map/chan/string
authorKen Thompson <ken@golang.org>
Fri, 12 Dec 2008 00:09:45 +0000 (16:09 -0800)
committerKen Thompson <ken@golang.org>
Fri, 12 Dec 2008 00:09:45 +0000 (16:09 -0800)
(they must be pointers)

R=r
OCL=21009
CL=21009

src/cmd/gc/dcl.c

index c2754f0da4810a908b40c1a47be66b999024ff53..5e50d1e78c2260a396dfbcf76426d11ed5f839ce 100644 (file)
@@ -483,8 +483,18 @@ loop:
        if(n->op != ODCLFIELD || n->type == T)
                fatal("stotype: oops %N\n", n);
 
-       if(n->type->etype == TARRAY && n->type->bound < 0)
-               yyerror("type of a structure field cannot be an open array");
+       switch(n->type->etype) {
+       case TARRAY:
+               if(n->type->bound < 0)
+                       yyerror("type of a structure field cannot be an open array");
+               break;
+
+       case TCHAN:
+       case TMAP:
+       case TSTRING:
+               yyerror("%T can exist only in pointer form", n->type);
+               break;
+       }
 
        switch(n->val.ctype) {
        case CTSTR:
@@ -732,6 +742,15 @@ addvar(Node *n, Type *t, int ctxt)
                pushdcl(s);
        }
 
+       if(t != T) {
+               switch(t->etype) {
+               case TCHAN:
+               case TMAP:
+               case TSTRING:
+                       yyerror("%T can exist only in pointer form", t);
+               }
+       }
+
        redeclare("variable", s);
        s->vargen = gen;
        s->oname = n;