Commit 74ee51ee authored by Russ Cox's avatar Russ Cox

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

Fixes #2827.

R=ken2
CC=golang-dev
https://golang.org/cl/5638045
parent 98257750
......@@ -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.
......
......@@ -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.
......
......@@ -30,6 +30,10 @@ func main(){
switch r.(type) {
case io.Writer:
}
// Issue 2827.
switch _ := r.(type) { // ERROR "invalid variable name _"
}
}
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