From 73612ddbfdaa5cabf51a2d2b77db6f158d17802a Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 10 Jun 2013 15:58:32 -0700 Subject: [PATCH] go.tools/cmd/cover: handle empty select Putting a coverage counter inside select{} is invalid Go. R=adonovan CC=golang-dev https://golang.org/cl/10175043 --- cmd/cover/cover.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 }