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/gopls: various analyzers panic #42857

Open
pjweinb opened this issue Nov 27, 2020 · 1 comment
Open

x/tools/gopls: various analyzers panic #42857

pjweinb opened this issue Nov 27, 2020 · 1 comment

Comments

@pjweinb
Copy link

@pjweinb pjweinb commented Nov 27, 2020

With gopls at tip, and go either at 1.15.1 or at tip, internal/lsp/testdata/semantic/a.go causes several analyzers to panic.

a.go contains code that will not build, and some analyzers panic on a type assertion where the types look like []interface{}.(string).

gopls will run analyzers on code that does not build, so it can test proposed fixes,
that is, in cache/analysis.go:325:

		data.err = errors.Errorf("analysis skipped due to errors in package: %v", pkg.GetErrors())
		return data
}

the test cannot be replaced by if len(pgk.GetErrors()) > 0, because then the tests for proposed fixes fail.

Most of the tests for analyzers won't run on files that don't build (nor will the tests in internal/lsp/source) so one could argue that these analyzers, at least, aren't intended to work on such code. Choices seem to be:

  • Put up with panic messages from gopls (bad user experience)
  • Fix the analyzers one by one (whack-a-mole)
  • For code that does not build, only run the analyzers that propose fixes (contributions welcome)
  • Do a more careful job at analysis.go:325 in deciding whether to run analyzers (contributions welcome)
  • Fix a.go so it doesn't trigger panics (push the problem off into the future)
@gopherbot gopherbot added this to the Unreleased milestone Nov 27, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Nov 28, 2020

Change https://golang.org/cl/273766 mentions this issue: go/analysis: avoid panic in ifaceassart

@stamblerre stamblerre removed this from the Unreleased milestone Nov 30, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Nov 30, 2020
gopherbot pushed a commit to golang/tools that referenced this issue Nov 30, 2020
Presently ifaceassert.go panics if given asserts whose
types reduce to
[]interface{}.(string)
which is illegal Go. Its tests won't even run on such code, but
gopls will happily invoke it. This CL adds a test for nil.

See golang/go#42857

Change-Id: I2791f4bd0b58559e65e6590822ac8f4123989273
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273766
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants