golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.06k stars 17.68k forks source link

cmd/cover: inconsistent NumStmt with prometheus #45361

Open catenacyber opened 3 years ago

catenacyber commented 3 years ago

What version of Go are you using (go version)?

$ go version
go version go1.16.2 linux/amd64

Does this issue reproduce with the latest release?

It is indeed the latest release

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/.go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/.go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2943966716=/tmp/go-build -gno-record-gcc-switches"

What did you do?

git clone https://github.com/prometheus/prometheus cd prometheus/promql/parser go test -coverprofile=wrong.out go tool cover -html wrong.out

What did you expect to see?

Get the HTML coverage report

What did you see instead?

Error message cover: inconsistent NumStmt: changed from 2 to 1

The wrong.out contains indeed (running grep generated_parser.y.go wrong.out | grep 178

github.com/prometheus/prometheus/promql/parser/generated_parser.y.go:178.0,180.0 2 1
github.com/prometheus/prometheus/promql/parser/generated_parser.y.go:179.0,178.0 2 1
github.com/prometheus/prometheus/promql/parser/generated_parser.y.go:176.0,178.0 1 1
github.com/prometheus/prometheus/promql/parser/generated_parser.y.go:178.0,180.0 1 1

I found this by modifying the covermessage with adding %#+v about other fields

yufeiminds commented 2 years ago

It still does not work on my laptop.

Any update on this issue?

wojciech-sneller commented 1 year ago

I encountered the same problem with the latest Go 1.20. Unfortunately, it's in a proprietary software, but also applies to a generated file -- in our case by Ragel. I'll try to find reproducer for this.

catenacyber commented 1 year ago

friendly ping @golang/runtime ?

ywwg commented 1 year ago

This is also still broken for our repo and hampers development

catenacyber commented 1 year ago

@neild the line directive strikes again it seems (messing up line numbers between the generated file and the generating file)

dhubler commented 1 year ago

Is there a workaround? My project does have generated code from goyacc FWIW.

AlexanderYastrebov commented 1 year ago

It seems that //line directives inserted into generated parser by goyacc result in invalid entries in coverprofile. The workaround could be to disable line directives via -l flag, see https://github.com/zalando/skipper/pull/2450.