diff --git a/cmd/cover/cover.go b/cmd/cover/cover.go index d6ce70a87c..d13ac54a1e 100644 --- a/cmd/cover/cover.go +++ b/cmd/cover/cover.go @@ -107,6 +107,16 @@ func (f *File) Visit(node ast.Node) ast.Visitor { } } n.List = f.addCounters(n.Pos(), n.End(), n.List) + case *ast.SelectStmt: + // Don't annotate an empty select - creates a syntax error. + if n.Body == nil || len(n.Body.List) == 0 { + return nil + } + case *ast.SwitchStmt: + // Don't annotate an empty switch - creates a syntax error. + if n.Body == nil || len(n.Body.List) == 0 { + return nil + } } return f }