]> Cypherpunks repositories - gostls13.git/commit
cmd/cover: change covered block for switch/select case to exclude expression
authorRuss Cox <rsc@golang.org>
Thu, 3 Nov 2016 00:18:47 +0000 (20:18 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 3 Nov 2016 16:13:06 +0000 (16:13 +0000)
commita4a4d43028ba20ecec50ef761012d17800553cde
tree5ee02ac03f23ae9aa71215e9a859980445a6e806
parent95e809f0e525fca000ec634e1e8cc10d6cebdf30
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>
src/cmd/cover/cover.go
src/cmd/cover/testdata/test.go