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:
parent
0ee0dd6ea8
commit
26365e4e90
|
@ -220,6 +220,11 @@ func (f *File) Visit(node ast.Node) ast.Visitor {
|
||||||
if n.Body == nil || len(n.Body.List) == 0 {
|
if n.Body == nil || len(n.Body.List) == 0 {
|
||||||
return nil
|
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
|
return f
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ func testAll() {
|
||||||
testTypeSwitch()
|
testTypeSwitch()
|
||||||
testSelect1()
|
testSelect1()
|
||||||
testSelect2()
|
testSelect2()
|
||||||
|
testEmptySwitches()
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSimple() {
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue