diff --git a/src/cmd/cover/cover.go b/src/cmd/cover/cover.go index 222737571fb..b7d9125d60a 100644 --- a/src/cmd/cover/cover.go +++ b/src/cmd/cover/cover.go @@ -168,13 +168,13 @@ func (f *File) Visit(node ast.Node) ast.Visitor { case *ast.CaseClause: // switch for _, n := range n.List { clause := n.(*ast.CaseClause) - clause.Body = f.addCounters(clause.Pos(), clause.End(), clause.Body, false) + clause.Body = f.addCounters(clause.Colon+1, clause.End(), clause.Body, false) } return f case *ast.CommClause: // select for _, n := range n.List { clause := n.(*ast.CommClause) - clause.Body = f.addCounters(clause.Pos(), clause.End(), clause.Body, false) + clause.Body = f.addCounters(clause.Colon+1, clause.End(), clause.Body, false) } return f } diff --git a/src/cmd/cover/testdata/test.go b/src/cmd/cover/testdata/test.go index 71cb1153313..61b40eaa740 100644 --- a/src/cmd/cover/testdata/test.go +++ b/src/cmd/cover/testdata/test.go @@ -246,6 +246,18 @@ func testFunctionLiteral() { check(LINE, 2) }) { } + + x := 2 + switch x { + case func() int { check(LINE, 1); return 1 }(): + check(LINE, 0) + panic("2=1") + case func() int { check(LINE, 1); return 2 }(): + check(LINE, 1) + case func() int { check(LINE, 0); return 3 }(): + check(LINE, 0) + panic("2=3") + } } func testGoto() {