1
0
mirror of https://github.com/golang/go synced 2024-11-15 05:20:21 -07:00
go/src/cmd/cover
Russ Cox a4a4d43028 cmd/cover: change covered block for switch/select case to exclude expression
Consider a switch like

	switch x {
	case foo:
		f()
		g()
	}

Before, the coverage annotation for the block calling f and g included
in its position span the text for 'case foo:'. This looks nice in the coverage
report, but it breaks the invariant that coverage blocks are disjoint if
you have a more complex expression like:

	switch x {
	case func() int { return foo }():
		f()
		g()
	}

Then the coverage analysis wants to annotate the func literal body,
which overlaps with the case body, because the case body is considered
to begin at the case token.

Change the annotation for a case body to start just after the colon of
the case clause, avoiding any potential conflict with complex case
expressions. Could have started at the colon instead, but it seemed
less weird to start just after it.

Fixes #16540.

Change-Id: I1fec4bc2a53c7092e649dc0d4be1680a697cb79b
Reviewed-on: https://go-review.googlesource.com/32612
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-11-03 16:13:06 +00:00
..
testdata cmd/cover: change covered block for switch/select case to exclude expression 2016-11-03 16:13:06 +00:00
cover_test.go
cover.go cmd/cover: change covered block for switch/select case to exclude expression 2016-11-03 16:13:06 +00:00
doc.go
func.go
html.go
profile.go