Commit c7ab3327 authored by Ken Thompson's avatar Ken Thompson

restrict declarations of type map/chan/string

(they must be pointers)

R=r
OCL=21009
CL=21009
parent 73653841
...@@ -483,8 +483,18 @@ loop: ...@@ -483,8 +483,18 @@ loop:
if(n->op != ODCLFIELD || n->type == T) if(n->op != ODCLFIELD || n->type == T)
fatal("stotype: oops %N\n", n); fatal("stotype: oops %N\n", n);
if(n->type->etype == TARRAY && n->type->bound < 0) switch(n->type->etype) {
case TARRAY:
if(n->type->bound < 0)
yyerror("type of a structure field cannot be an open array"); 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) { switch(n->val.ctype) {
case CTSTR: case CTSTR:
...@@ -732,6 +742,15 @@ addvar(Node *n, Type *t, int ctxt) ...@@ -732,6 +742,15 @@ addvar(Node *n, Type *t, int ctxt)
pushdcl(s); 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); redeclare("variable", s);
s->vargen = gen; s->vargen = gen;
s->oname = n; s->oname = n;
......
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