go.tools/go/types: record lhs identifier in switch lhs := rhs.(type)

Added testcase.

R=adonovan
CC=golang-dev
https://golang.org/cl/11742043
This commit is contained in:
Robert Griesemer 2013-07-24 12:38:51 -07:00
parent d4f2f2d7fa
commit d0657ebb0d
2 changed files with 7 additions and 1 deletions

View File

@ -46,6 +46,11 @@ var sources = []string{
var i I var i I
var _ = i.m var _ = i.m
func _(s []int) { for i, x := range s {} } func _(s []int) { for i, x := range s {} }
func _(x interface{}) {
switch x := x.(type) {
case int:
}
}
`, `,
} }

View File

@ -356,6 +356,7 @@ func (check *checker) stmt(s ast.Stmt) {
check.invalidAST(s.Pos(), "incorrect form of type switch guard") check.invalidAST(s.Pos(), "incorrect form of type switch guard")
return return
} }
check.recordObject(lhs, nil) // lhs is implicitly declared in each cause clause
rhs = guard.Rhs[0] rhs = guard.Rhs[0]