diff --git a/go/types/stmt.go b/go/types/stmt.go index 42580bdd..fa60f64d 100644 --- a/go/types/stmt.go +++ b/go/types/stmt.go @@ -569,11 +569,11 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) { } check.openScope(s, "case") - defer check.closeScope() if clause.Comm != nil { check.stmt(inner, clause.Comm) } check.stmtList(inner, clause.Body) + check.closeScope() } case *ast.ForStmt: diff --git a/go/types/testdata/stmt0.src b/go/types/testdata/stmt0.src index 646c4189..4c840367 100644 --- a/go/types/testdata/stmt0.src +++ b/go/types/testdata/stmt0.src @@ -215,6 +215,17 @@ func selects() { case x /* ERROR send or receive */ : case a /* ERROR send or receive */ := ch: } + + // test for issue 9570: ch2 in second case falsely resolved to + // ch2 declared in body of first case + ch1 := make(chan int) + ch2 := make(chan int) + select { + case <-ch1: + var ch2 /* ERROR ch2 declared but not used */ chan bool + case i := <-ch2: + print(i + 1) + } } func gos() {