Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/go/packages: internal error: package ... without types was imported from ... #37617

Closed
mmcloughlin opened this issue Mar 3, 2020 · 11 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mmcloughlin
Copy link
Contributor

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

$ go version
go version go1.14 darwin/amd64

Does this issue reproduce with the latest release?

Yes, and not with prior releases.

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

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/michaelmcloughlin/Library/Caches/go-build"
GOENV="/Users/michaelmcloughlin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/michaelmcloughlin/Development/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/michaelmcloughlin/Development/avo/go.mod"
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=/var/folders/p5/84p384bs42v7pbgfx0db9gq80000gn/T/go-build266927286=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I ran into this problem when attempting to upgrade to Go 1.14 in my avo project. The lint CI job fails for Go 1.14:

mmcloughlin/avo#138

The error is actually in the asmdecl step, which is a standalone version of the asmdecl static analyzer in go vet:

https://github.com/mmcloughlin/avo/blob/6df701fe672f960f4aa5dde1424633110a857953/internal/cmd/asmdecl/main.go

// Command asmdecl reports mismatches between assembly files and Go declarations.
//
// Standalone version of the static analyzer in go vet.
package main

import (
	"golang.org/x/tools/go/analysis/passes/asmdecl"
	"golang.org/x/tools/go/analysis/singlechecker"
)

func main() { singlechecker.Main(asmdecl.Analyzer) }

The CI job compiles this binary and runs it over the whole project, with asmdecl ./....

What did you expect to see?

Under Go 1.13.8, running this over the whole avo project exits without error

$ go1.13.8 run ./internal/cmd/asmdecl/ ./...

I expected the same under Go 1.14.

What did you see instead?

$ go1.14 run ./internal/cmd/asmdecl/ ./...
asmdecl: internal error: package "fmt" without types was imported from "github.com/mmcloughlin/avo/attr"
exit status 1
@gopherbot gopherbot added this to the Unreleased milestone Mar 3, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 3, 2020
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 3, 2020
@dmitshur
Copy link
Contributor

dmitshur commented Mar 3, 2020

/cc @matloob per owners.

@atombender
Copy link

I'm getting this with go-sumtype. It fails on a single main.go file:

package main

import (
	"errors"
)

func main() {
	_ = errors.New("x")
}

Then:

$ go-sumtype main.go
internal error: package "errors" without types was imported from "command-line-arguments"

@matloob
Copy link
Contributor

matloob commented Apr 24, 2020

@atombender, go-sumtype does fail when run on main.go, but it looks like that's due to it using an old version of golang.org/x/tools/go/packages. When its dependency on go/tools is updated in its go.mod file (I updated it to v0.0.0-20200423205358-59e73619c742) the error no longer occurs.

@mmcloughlin I'm wondering if you could give me more specific instructions for reproducing locally?

@matloob matloob added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 24, 2020
mmcloughlin added a commit to mmcloughlin/avo that referenced this issue Apr 25, 2020
Add go 1.14 to CI testing. Upgrade golang.org/x/tools dependency to resolve golang/go#37617.
@mmcloughlin
Copy link
Contributor Author

@matloob I'm not seeing this in the latest x/tools release. This can be closed as far as I'm concerned. Thanks!

@matloob
Copy link
Contributor

matloob commented Apr 27, 2020

Great, thanks! Will close this issue.

@matloob matloob closed this as completed Apr 27, 2020
RussellLuo added a commit to RussellLuo/kun that referenced this issue Oct 29, 2020
@golang golang locked and limited conversation to collaborators Apr 27, 2021
@thepudds
Copy link
Contributor

Just a quick comment in case someone else see this, though probably not super helpful...

Right now, I'm seeing a couple different flavors of this issue:

2021/12/12 21:03:14 internal error: package "errors" without types was imported from "golang.zx2c4.com/go118/netip"

and

2021/12/12 21:01:39 internal error: package "sort" without types was imported from "net"

Two possible correlating factors:

  1. I am using tip (with a shortcut of export PATH=$(gotip env GOROOT)/bin:$PATH, version is go version devel go1.18-49b7c9c Sun Dec 12 16:09:13 2021 +0000 linux/amd64 )
  2. I am juggling a bunch of nested modules with a series of replace directives. Some chance I have a mistake there, though I think I still see the error after removing the replace directives.

If I sort this out more, I will add more here, or open a new issue.

@thepudds
Copy link
Contributor

thepudds commented Dec 12, 2021

Updating to the golang.org/x/tools@latest (v0.1.8) and rebuilding my binary seems to have solved the issue.

That wasn't the first thing I tried because I was seeing the problem with a relatively recent version of x/tools:

golang.org/x/tools v0.1.7

So maybe something related to x/tools being recent, but too far behind tip?

(And perhaps similar to #49164, #49159, marwan-at-work/mod#9, and perhaps others as I google a bit more now).

@matloob I am going to re-open this issue so it at least pops up on your radar or in case something like a different error is useful, but please of course feel free to close if no action is warranted here.

Thanks, and sorry for the noise!

@seankhliao
Copy link
Member

given the length of time passed, new issues should probably be filed as new issues.

alecthomas pushed a commit to alecthomas/go-check-sumtype that referenced this issue Mar 11, 2023
This commit resolves an issue where on Go 1.19, errors of the following
form appear, when an internal package "xyz" would import from the
standard library.

    internal error: package "fmt" without types was imported from "xyz"

This problem was discussed in the Go issue tracker here as well:
golang/go#37617

Closes BurntSushi/go-sumtype#17
maciej added a commit to maciej/asasalint that referenced this issue Mar 29, 2023
Old tools version casued the issue described in golang/go#37617
to manifest when validating certain codebases.
Bumping golang.org/x/tools to latest version resolves that.
storjBuildBot pushed a commit to storj/ci that referenced this issue Apr 11, 2023
I have seen errors similar to golang/go#37617:

Executing checks failed with:

```
check-errs ./...
errs: internal error: package "errors" without types was imported from "storj.io/gateway-mt/pkg/errdata"
errs: internal error: package "context" without types was imported from "storj.io/gateway-mt/pkg/backoff"
```

Looks like the solution - bump x/tools as suggested  in the mentioned issue - worked well.

Change-Id: Ia871dafb1a42a9e6bb99feea7ce4885cc50786f2
@nikoremi97
Copy link

In case someone has this issue nowadays..... update the deps!
go get -u ./...

sometimes, idk why, the go tools package is installed in a previous version.

alingse pushed a commit to alingse/asasalint that referenced this issue May 22, 2023
Old tools version casued the issue described in golang/go#37617
to manifest when validating certain codebases.
Bumping golang.org/x/tools to latest version resolves that.
@rthille
Copy link

rthille commented Jun 7, 2023

Still seeing this issue after running go get -u ./...

2023-06-07T16:39:05-0700$ gosec ./... || echo "failed"
[gosec] 2023/06/07 16:39:08 Including rules: default
[gosec] 2023/06/07 16:39:08 Excluding rules: default
[gosec] 2023/06/07 16:39:08 Import directory: /Users/robertthille/dev/[REDACTED]
2023/06/07 16:39:08 internal error: package "fmt" without types was imported from "command-line-arguments"
failed
2023-06-07T16:39:10-0700$ 

@chrissheridan-zh
Copy link

I'm getting this issue now as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

10 participants