mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
cmd/gc: disallow switch _ := v.(type)
Fixes #2827. R=ken2 CC=golang-dev https://golang.org/cl/5638045
This commit is contained in:
parent
98257750f4
commit
74ee51ee92
|
@ -423,7 +423,7 @@ simple_stmt:
|
||||||
yyerror("expr.(type) must be alone in list");
|
yyerror("expr.(type) must be alone in list");
|
||||||
if($1->next != nil)
|
if($1->next != nil)
|
||||||
yyerror("argument count mismatch: %d = %d", count($1), 1);
|
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);
|
yyerror("invalid variable name %N in type switch", $1->n);
|
||||||
else
|
else
|
||||||
$$->left = dclname($1->n->sym); // it's a colas, so must not re-use an oldname.
|
$$->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");
|
yyerror("expr.(type) must be alone in list");
|
||||||
if((yyvsp[(1) - (3)].list)->next != nil)
|
if((yyvsp[(1) - (3)].list)->next != nil)
|
||||||
yyerror("argument count mismatch: %d = %d", count((yyvsp[(1) - (3)].list)), 1);
|
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);
|
yyerror("invalid variable name %N in type switch", (yyvsp[(1) - (3)].list)->n);
|
||||||
else
|
else
|
||||||
(yyval.node)->left = dclname((yyvsp[(1) - (3)].list)->n->sym); // it's a colas, so must not re-use an oldname.
|
(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) {
|
switch r.(type) {
|
||||||
case io.Writer:
|
case io.Writer:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue 2827.
|
||||||
|
switch _ := r.(type) { // ERROR "invalid variable name _"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue