1
0
mirror of https://github.com/golang/go synced 2024-11-25 00:07:56 -07:00

cmd/gc: disallow switch _ := v.(type)

Fixes #2827.

R=ken2
CC=golang-dev
https://golang.org/cl/5638045
This commit is contained in:
Russ Cox 2012-02-06 12:35:29 -05:00
parent 98257750f4
commit 74ee51ee92
3 changed files with 6 additions and 2 deletions

View File

@ -423,7 +423,7 @@ simple_stmt:
yyerror("expr.(type) must be alone in list");
if($1->next != nil)
yyerror("argument count mismatch: %d = %d", count($1), 1);
else if($1->n->op != ONAME && $1->n->op != OTYPE && $1->n->op != ONONAME)
else if(($1->n->op != ONAME && $1->n->op != OTYPE && $1->n->op != ONONAME) || isblank($1->n))
yyerror("invalid variable name %N in type switch", $1->n);
else
$$->left = dclname($1->n->sym); // it's a colas, so must not re-use an oldname.

View File

@ -2714,7 +2714,7 @@ yyreduce:
yyerror("expr.(type) must be alone in list");
if((yyvsp[(1) - (3)].list)->next != nil)
yyerror("argument count mismatch: %d = %d", count((yyvsp[(1) - (3)].list)), 1);
else if((yyvsp[(1) - (3)].list)->n->op != ONAME && (yyvsp[(1) - (3)].list)->n->op != OTYPE && (yyvsp[(1) - (3)].list)->n->op != ONONAME)
else if(((yyvsp[(1) - (3)].list)->n->op != ONAME && (yyvsp[(1) - (3)].list)->n->op != OTYPE && (yyvsp[(1) - (3)].list)->n->op != ONONAME) || isblank((yyvsp[(1) - (3)].list)->n))
yyerror("invalid variable name %N in type switch", (yyvsp[(1) - (3)].list)->n);
else
(yyval.node)->left = dclname((yyvsp[(1) - (3)].list)->n->sym); // it's a colas, so must not re-use an oldname.

View File

@ -30,6 +30,10 @@ func main(){
switch r.(type) {
case io.Writer:
}
// Issue 2827.
switch _ := r.(type) { // ERROR "invalid variable name _"
}
}