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: analysis does not work if there's a type error even with RunDespiteErrors: true #51014

Closed
kdy1 opened this issue Feb 4, 2022 · 2 comments
Assignees
Labels
Analysis NeedsInvestigation Tools
Milestone

Comments

@kdy1
Copy link

@kdy1 kdy1 commented Feb 4, 2022

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

❯ go version
go version go1.17.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes. The problematic code is latest.

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kdy1/Library/Caches/go-build"
GOENV="/Users/kdy1/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kdy1/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kdy1/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.17.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.6/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pw/7l7d6f6s6ngb9z17pc912mtc0000gn/T/go-build3641127775=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
	"golang.org/x/tools/go/analysis/multichecker"
	"my.pkg/internal/devtools/fixer/slicefix"
)

func main() {
	//singlechecker.Main(&slicefix.SliceFix)
	multichecker.Main(&slicefix.SliceFix)
}

Where slicefix is

package slicefix

import (
	"log"

	"golang.org/x/tools/go/analysis"
)

var (
	SliceFix = analysis.Analyzer{
		Name:             "slicefix",
		Doc:              "Auto dereference of slices",
		Run:              run,
		RunDespiteErrors: true,
	}
)

func run(pass *analysis.Pass) (interface{}, error) {
	log.Fatalf("Run")

	return nil, nil
}

What did you expect to see?

I expected the analysis to be run, because I set RunDespiteErrors to true.

What did you see instead?

/Users/kdy1/projects/tsc/codemap/loc.go:27:23: invalid argument: arr (variable of type *[]string) for len
fixer: error during loading
@gopherbot gopherbot added the Tools label Feb 4, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 4, 2022
@toothrot toothrot added the NeedsInvestigation label Feb 4, 2022
@timothy-king timothy-king added the Analysis label Feb 4, 2022
@zpavlinovic
Copy link
Contributor

@zpavlinovic zpavlinovic commented Feb 5, 2022

I was able to reproduce it and got the same issue with copylock analyzer. Working on a fix.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 8, 2022

Change https://go.dev/cl/383974 mentions this issue: go/analysis/tools/internal/checker: add support for RunDespiteError

gopherbot pushed a commit to golang/tools that referenced this issue Feb 17, 2022
When there is a syntax or type error, we should run the analyzers that
have the RunDespiteError flag set to true, if any. The current code just
skips any analysis whatsoever.

For golang/go#51014

Change-Id: I5c3e5f3d9e2e8d791e9996b9114bb719e89daf30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/383974
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Tim King <taking@google.com>
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis NeedsInvestigation Tools
Projects
None yet
Development

No branches or pull requests

5 participants