mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: "invalid variable name x in type switch", where x is a name of a constant
Small fix: looks like a short variable declaration with a type switch checks to make sure the variable used had valid shape (ONAME, OTYPE, or ONONAME) and rejects everything else. Then a new variable is declared. If the symbol contained in the declaration was a named OLITERAL (still a valid identifier obviously) it would be rejected, even though a new variable would have been declared. Fix adds this case to the check. Added a test case from issue12413. Fixes #12413 Change-Id: I150dadafa8ee5612c867d58031027f2dca8c6ebc Reviewed-on: https://go-review.googlesource.com/15760 Reviewed-by: Minux Ma <minux@golang.org> Run-TryBot: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
3b000b3eae
commit
b60c8203ea
3 changed files with 21 additions and 2 deletions
|
|
@ -1586,7 +1586,7 @@ yydefault:
|
|||
}
|
||||
if yyDollar[1].list.Next != nil {
|
||||
Yyerror("argument count mismatch: %d = %d", count(yyDollar[1].list), 1)
|
||||
} else if (yyDollar[1].list.N.Op != ONAME && yyDollar[1].list.N.Op != OTYPE && yyDollar[1].list.N.Op != ONONAME) || isblank(yyDollar[1].list.N) {
|
||||
} else if (yyDollar[1].list.N.Op != ONAME && yyDollar[1].list.N.Op != OTYPE && yyDollar[1].list.N.Op != ONONAME && (yyDollar[1].list.N.Op != OLITERAL || yyDollar[1].list.N.Name == nil)) || isblank(yyDollar[1].list.N) {
|
||||
Yyerror("invalid variable name %s in type switch", yyDollar[1].list.N)
|
||||
} else {
|
||||
yyVAL.node.Left = dclname(yyDollar[1].list.N.Sym)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue