From d0657ebb0d5ab938afb6003df4a8bf770dd45b27 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 24 Jul 2013 12:38:51 -0700 Subject: [PATCH] go.tools/go/types: record lhs identifier in switch lhs := rhs.(type) Added testcase. R=adonovan CC=golang-dev https://golang.org/cl/11742043 --- go/types/resolver_test.go | 7 ++++++- go/types/stmt.go | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go/types/resolver_test.go b/go/types/resolver_test.go index bb1ed913..99bf62ec 100644 --- a/go/types/resolver_test.go +++ b/go/types/resolver_test.go @@ -45,7 +45,12 @@ var sources = []string{ func (_ T) m() {} var i I 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: + } + } `, } diff --git a/go/types/stmt.go b/go/types/stmt.go index a55bb5bd..dd35dfc8 100644 --- a/go/types/stmt.go +++ b/go/types/stmt.go @@ -356,6 +356,7 @@ func (check *checker) stmt(s ast.Stmt) { check.invalidAST(s.Pos(), "incorrect form of type switch guard") return } + check.recordObject(lhs, nil) // lhs is implicitly declared in each cause clause rhs = guard.Rhs[0]