1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00

cmd/cover: fix handling of empty type switch

Just missed a case (ha!) in the tree walk. Dup the code for an empty switch, add test.

Fixes #10163.

Change-Id: I3d50ab6cb450ca21e87213291eaab8cbe924fac5
Reviewed-on: https://go-review.googlesource.com/7641
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Rob Pike 2015-03-16 14:52:01 -07:00
parent 0ee0dd6ea8
commit 26365e4e90
2 changed files with 23 additions and 0 deletions

View File

@ -220,6 +220,11 @@ func (f *File) Visit(node ast.Node) ast.Visitor {
if n.Body == nil || len(n.Body.List) == 0 {
return nil
}
case *ast.TypeSwitchStmt:
// Don't annotate an empty type switch - creates a syntax error.
if n.Body == nil || len(n.Body.List) == 0 {
return nil
}
}
return f
}

View File

@ -22,6 +22,7 @@ func testAll() {
testTypeSwitch()
testSelect1()
testSelect2()
testEmptySwitches()
}
func testSimple() {
@ -175,3 +176,20 @@ func testSelect2() {
}
}
}
// Empty control statements created syntax errors. This function
// is here just to be sure that those are handled correctly now.
func testEmptySwitches() {
check(LINE, 1)
switch 3 {
}
check(LINE, 1)
switch i := (interface{})(3).(int); i {
}
check(LINE, 1)
go func() {
check(LINE, 1)
select {}
}()
check(LINE, 1)
}