Skip to content

go/types: go vet reporting incorrect "imported but not used" error #23914

Closed
@somersf

Description

@somersf

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

This issue appeared in a canary build/test of part of our Go codebase, using go master HEAD recently.

Does this issue reproduce with the latest release?

This issue is not present in the released go1.10 or go1.9.4 versions.

This regression seems to have appeared in HEAD shortly after go1.11 development opened.

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

GOOS="linux" GOARCH="amd64"
GOOS="darwin" GOARCH="amd64"

What did you do?

Create a package issue containing two seperate files:

a.go:

package issue

import "regexp"

type Y interface {
	X

	Expr() *regexp.Regexp
}

b.go:

package issue

import "regexp"

type X interface {
	Exprs() []*regexp.Regexp
}

To reproduce, use a go HEAD version after approximately Feb 13th, and run:

$ cd issue

$ go vet .
# _/home/user/go-project/issue
./b.go:3:8: "regexp" imported but not used
vet: typecheck failures

Changing the order the files are presented to go vet changes the behavior:

$ cd issue

$ go vet a.go b.go
# command-line-arguments
./b.go:3:8: "regexp" imported but not used
vet: typecheck failures

$ go vet b.go a.go             # <--- This order succeeds
$ echo $?
0

Additional Information

From our testing logs:
go version devel +ce5fa6d5e9 Tue Feb 13 16:00:30 2018 +0000 linux/amd64 has this regression.
go version devel +c52e27e68d Sun Feb 11 20:41:48 2018 +0000 linux/amd64 succeeds.

A git bisect run, checking between HEAD (+7a1347a1a1 on 2018-02-18) and +c52e27e68d indicates that the regression may have been introduced or uncovered as part of commit dd44895 (merged to master Feb 12th).

What did you expect to see?

go vet should succeed on these input files, regardless of the file input order.

What did you see instead?

go vet is erroneously reporting "regexp" imported but not used when the package is being used for a return type.

The behavior also appears to be sensitive to the order in which go vet processes the input files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.early-in-cycleA change that should be done early in the 3 month dev cycle.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions