Skip to content

cmd/go: coverpkg=all fails when dot imports . are present #23432

@ghost

Description

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

go1.10beta2

go version devel +594668a5a9 Thu Jan 11 17:44:08 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

With go1.9.2 it works fine:

$ go test -coverpkg=all ./...
warning: no packages being tested depend on archive/tar
...
warning: no packages being tested depend on vendor/golang_org/x/text/unicode/norm
?   	demo	[no test files]

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

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/myself/go/demo"
GORACE=""
GOROOT="/Users/myself/.gvm/gos/go1.9.2"
GOTOOLDIR="/Users/myself/.gvm/gos/go1.9.2/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1_/931p_3ms15b07mhkkmmzz1qc0000gp/T/go-build361849763=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

Created main.go:

package main

import . "fmt"

func main() {
	Println("example")
}

Ran test with -coverpkg=all

$ go test -coverpkg=all ./...
# demo
./main.go:5: invalid array index 0 (out of bounds for 0-element array)
./main.go:9: GoCover_0 redeclared in this block
	previous declaration during import "fmt"

What did you expect to see?

Should have no errors, same as when -coverpkg=all is not specified:

$  go test  ./...
?   	demo	[no test files]

What did you see instead?

-coverpkg=all seems to be adding variables GoCover_0 to the current package as well as the . imported "fmt" package. That causes the current package to not compile because GoCover_0 is redeclared in this package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions