go-critic: panic in load embedded ruleguard rules: can't load fmt

I was trying out the latest v0.6.0 (https://github.com/go-critic/go-critic/releases/tag/v0.6.0) on Windows and it failed with:

> gocritic ./...
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt

goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.9()
        /home/isharipov/CODE/go-critic3/checkers/checkers.go:47 +0x3b4

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 44 (21 by maintainers)

Commits related to this issue

Most upvoted comments

type-checking package "fmt" failed (
  /usr/local/go/src/fmt/errors.go:7:8: could not import errors (
    type-checking package "errors" failed (
      /usr/local/go/src/errors/wrap.go:8:2: could not import internal/reflectlite (
        type-checking package "internal/reflectlite" failed (
          /usr/local/go/src/internal/reflectlite/value.go:10:2: could not import runtime (
            type-checking package "runtime" failed (
                /usr/local/go/src/runtime/chan.go:21:2: could not import internal/abi (
                  type-checking package "internal/abi" failed (
                    /usr/local/go/src/internal/abi/abi.go:117:19: undeclared name: any
)))))))))

Digging a bit deeper, this is not really the same issue, but just incompatibility with Go 1.18 while trying to load the source files.

Is this worth opening a new issue for, or should I just consider new Go versions unsupported until there’s a new go-critic release (that probably needs to be compiled with the new Go version so the type-checking works correctly)?

In the interim, it might make sense to remove the pre-built release binaries and recommend building from source.

So I’ve been debugging a bit: 2021-10-18 17_39_49-Window

It looks like GOROOT of the compilation location is being used due to a call to https://pkg.go.dev/go/importer#ForCompiler (in https://github.com/quasilyte/go-ruleguard/blob/84a8b0bc91ee08ce7c77baf5214dea1bc403ea34/ruleguard/importer.go#L45). Effectively, it tries to use GOROOT of the computer doing the building. Not sure what the fix is yet though.

Can confirm it works for me with the go-ruleguard update.

Looks like ruleguard uses go/importer somewhat incorrectly. I’m trying to figure out how to address that.

I tried building the latest gocritic for windows in a linux container and running it. It does seem to run fine, but, I also didn’t do any extensive testing. The issue can always be reopened when someone encounters an issue.

@egonelbre hmm, I knew about go env VAR syntax, but didn’t know that it supports a list of vars. Good to know, thank you! I’m learning new things every day with you. 😃

Yes, it outputs things to set the environment variable by default. You can use go env GOPATH GOROOT GOOS GOARCH to get the specific values.

If I compile it from source then it works fine.

Sidenote: go generate ./... doesn’t work on tip.

Note, gocritic check ./... fails with the same error.