Skip to content

internal compiler error: have package "main" want package "..." #3583

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

Closed
4 tasks done
tsaarni opened this issue Feb 10, 2023 · 8 comments
Closed
4 tasks done

internal compiler error: have package "main" want package "..." #3583

tsaarni opened this issue Feb 10, 2023 · 8 comments
Labels
question Further information is requested

Comments

@tsaarni
Copy link

tsaarni commented Feb 10, 2023

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc.).
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

After upgrading to go1.20 typecheck results in compiler error for tools.go file. The file is following a common pattern described here.

The error looks like following

tools.go:1: : # example.com/tools
<unknown line number>: internal compiler error: have package "main" (0xc00043b9a0), want package "github.com/onsi/ginkgo/v2/ginkgo" (0xc00043b900)

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new (typecheck)
//go:build tools

See the code example below to reproduce the error.

Possibly related to golang/go#54542

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.51.1 built from (unknown, mod sum: "h1:N5HD/x0ZrhJYsgKWyz7yJxxQ8JKR0Acc+FOP7QtGSAA=") on (unknown)

Configuration file

No configuration file.

Go environment

$ go version && go env
go version go1.20 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tsaarni/.cache/go-build"
GOENV="/home/tsaarni/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tsaarni/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tsaarni/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tsaarni/sdk/go1.20"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tsaarni/sdk/go1.20/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/tsaarni/package/tools/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3751123669=/tmp/go-build -gno-record-gcc-switches"```

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

Code example or link to a public repository

mkdir tools
cd tools

go mod init example.com/tools

cat > tools.go <<EOF
//go:build tools

package tools

// nolint:typecheck
import _ "github.com/onsi/ginkgo/v2/ginkgo"
EOF

go get github.com/onsi/ginkgo/v2/ginkgo

golangci-lint run --build-tags=tools
@tsaarni tsaarni added the bug Something isn't working label Feb 10, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 10, 2023

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Feb 10, 2023

Hello,

It is the same expected behavior as go build:

$ go build -tags=tools .
tools.go:6:8: import "github.com/onsi/ginkgo/v2/ginkgo" is a program, not an importable package

So I think it is something related to Go.

@tsaarni
Copy link
Author

tsaarni commented Feb 10, 2023

Thank you for your response @ldez. I have modified the issue description a bit. Originally, it included also

tools.go:5:8: import "github.com/onsi/ginkgo/v2/ginkgo" is a program, not an importable package (typecheck)

but that error can be removed by adding // nolint:typecheck like shown in the code example.

The error that I'm reporting is

tools.go:1: : # example.com/tools
<unknown line number>: internal compiler error: have package "main" (0xc00042b9f0), want package "github.com/onsi/ginkgo/v2/ginkgo" (0xc00042b950)

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new (typecheck)
//go:build tools

@ldez
Copy link
Member

ldez commented Feb 10, 2023

typecheck is not a real linter but a way to catch compilation errors.

Note: The directive // nolint:typecheck must not have spaces after //: -> //nolint:typecheck. But even like that the directive will not be applied because the error reported by typecheck cannot be ignored.

So I think that something has changed in the go tool chain.

@tsaarni
Copy link
Author

tsaarni commented Feb 10, 2023

Ah, sorry my mistake! Thank you for clarification.

However, any use of nolint removes not an importable package error, while the internal compiler error remains. The compiler error is possibly related to golang/go#54542.

@ldez
Copy link
Member

ldez commented Feb 10, 2023

It doesn't seem related to this issue.

@tsaarni
Copy link
Author

tsaarni commented Feb 10, 2023

Ok, my guess was purely based on similar error mentioned there

<unknown line number>: internal compiler error: have package "lie" (0xc0003dd130), want package "a" (0xc0003dcfa0)

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Mar 17, 2024
@ldez
Copy link
Member

ldez commented Mar 22, 2024

The problem seems fixed now:

$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.57.0 golangci-lint run --build-tags=tools
$

@ldez ldez closed this as completed Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants