diff options
author | zikaeroh <zikaeroh@gmail.com> | 2020-03-11 17:02:50 -0700 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2020-03-13 14:29:27 +0000 |
commit | c3b9042132efc4e9f3485cd12b07acd1ca9c7d57 (patch) | |
tree | 472a49b2f8ca66a00cbfd1fce856e9ec407ea76b /src/cmd/cover | |
parent | c6bcdeafd2a2f11373dec9a82fccc75d332cd0cc (diff) | |
download | go-c3b9042132efc4e9f3485cd12b07acd1ca9c7d57.tar.gz go-c3b9042132efc4e9f3485cd12b07acd1ca9c7d57.zip |
cmd/cover: skip function declarations with blank names
Function declarations with blank ("_") names do not introduce a binding,
and therefore cannot be referenced or executed (in fact, they do not
make it into the final compiled binary at all). As such, counters
defined while annotating their bodies will always be zero.
These types of functions are commonly used to create compile-time
checks (e.g., stringer) which are not expected to be executed.
Skip over these functions when annotating a file, preventing the unused
counters from being generated and appearing as uncovered lines in
coverage reports.
Fixes #36264
Change-Id: I6b516cf43c430a6248d68d5f483a3902253fbdab
Reviewed-on: https://go-review.googlesource.com/c/go/+/223117
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/cover')
-rw-r--r-- | src/cmd/cover/cover.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cmd/cover/cover.go b/src/cmd/cover/cover.go index e04c8834bd..360f9aeb06 100644 --- a/src/cmd/cover/cover.go +++ b/src/cmd/cover/cover.go @@ -293,6 +293,11 @@ func (f *File) Visit(node ast.Node) ast.Visitor { ast.Walk(f, n.Assign) return nil } + case *ast.FuncDecl: + // Don't annotate functions with blank names - they cannot be executed. + if n.Name.Name == "_" { + return nil + } } return f } |