• Russ Cox's avatar
    cmd/cover: change covered block for switch/select case to exclude expression · a4a4d430
    Russ Cox authored
    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: 's avatarAndrew Gerrand <adg@golang.org>
    a4a4d430
Name
Last commit
Last update
.github Loading commit data...
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...