-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: "invalid variable name x in type switch", where x is a n…
…ame 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 golang#12413 Change-Id: I150dadafa8ee5612c867d58031027f2dca8c6ebc Reviewed-on: https://go-review.googlesource.com/15760 Reviewed-by: Minux Ma <[email protected]> Run-TryBot: Minux Ma <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
- Loading branch information
1 parent
3b000b3
commit b60c820
Showing
3 changed files
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// compile | ||
|
||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// issue 12413: invalid variable name x in type switch: code would fail | ||
// to compile if the variable used in the short variable declaration was | ||
// previously declared as a constant. | ||
|
||
package main | ||
|
||
func main() { | ||
const x = 42 | ||
switch x := interface{}(nil).(type) { | ||
default: | ||
_ = x | ||
} | ||
} |