]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: disallow switch _ := v.(type)
authorRuss Cox <rsc@golang.org>
Mon, 6 Feb 2012 17:35:29 +0000 (12:35 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 6 Feb 2012 17:35:29 +0000 (12:35 -0500)
Fixes #2827.

R=ken2
CC=golang-dev
https://golang.org/cl/5638045

src/cmd/gc/go.y
src/cmd/gc/y.tab.c
test/typeswitch3.go

index c44aabf398c482ddadd96d7899ab91717800d5ce..31909635876f427029150e6f4bba7053ed7a4b41 100644 (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.
index 9bf1019e9d722f58ca4293538841ffd5c9f182d4..2ad3d89b34fe42bea502fcb049ff3ca4fa814e2c 100644 (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.
index 078980146f8b4aedf3eaaca339ff8735025acfc9..e11da7d747f9ec6802cfe7b98ba51ae5e78b2ae5 100644 (file)
@@ -30,6 +30,10 @@ func main(){
        switch r.(type) {
        case io.Writer:
        }
+       
+       // Issue 2827.
+       switch _ := r.(type) {  // ERROR "invalid variable name _"
+       }
 }