This CL fixes a bug (#70149) in gopls/internal/golang/pkgdoc.go
in which a call to fset.File(file.Pos()) would return nil
because when file points to an empty ast.File, Pos() returns NoPos.
Instead, we should use file.FileStart, which is (in principle)
always valid even for an empty file. However, there is a separate
bug in go1.23 (#70162) that means FileStart is invalid whenever
Pos() is. So, this fix only works with go1.24, and there's no
real workaround short of the additional logic this CL adds to
parsego.Parse, which at least covers all of gopls.
Also, we audit all of x/tools for similar faulty uses of Pos()
and replace them with FileStart. In future, we should use File.Pos
only for its specific meaning related to the package decl.
Fixesgolang/go#70149
Updates golang/go#70162
Change-Id: Ic8cedfe912e44a0b4eb6e5e6874a6266d4be9076
Reviewed-on: https://go-review.googlesource.com/c/tools/+/624437
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
CL 589118 is changing the format of go/types errors.
Update tests and the unusedvariable analyzer to be tolerant of this new
format.
For golang/go#67685
Change-Id: Ic1d3e663973edac3dcc6d0d6cc512fffd595eeb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589455
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Starting soon, go/types will quote some user defined names in error
messages as `a'. Update tests to be tolerant of the new syntax.
Notably, logic in the unusedvariable analyzer which extracts the
variable name had to be updated.
Change-Id: I091ab2af9b5ed82aa7eacad8f4a9405f34fcded7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/571517
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
The "missing Diagnostic.Code" assertion checks an invariant
that isn't guaranteed. This change downgrades it to a bug.Reportf.
Also, we add a similar assertion to analysistest.RunWithSuggestedFixes
which has much better coverage of all the analyzer's different
ways of constructing a SuggestedFix, unlike gopl's own superficial
tests of each analyzer it carries. (This assertion may be enabled
only for analyzers in x/tools, since the invariant is stricter
than is required by the public API.)
Also, fix a couple of places in unusedvariable where it could
conceivably return a fix with no TextEdits; they are not intended
to be lazy fixes.
Fixesgolang/go#65578
Change-Id: I5ed6301b028d184ea896988ca8f210fb8f3dd64f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/562397
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Interestingly, this turned up one false positive of the form
var hook = func(err error) {}
where other build-tagged files not visible to the analysis
assigned other values to hook that actually used the
parameter.
Change-Id: I7d230160fd7e5ad67ade7b6e57db150bf68fa1c3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/560716
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This change moves MustExtractDoc to a higher (but still internal)
directory so that it can be used from gopls, and converts all
of gopls' analyzers into the form it expects.
It also adds the corresponding pkg.go.dev page to
each Analyzer.URL, and shows this link in the generated markdown.
Even if ExtractDoc is never published (see golang/go#61315) it
is still convenient to use in x/tools.
Fixesgolang/go#63820
Change-Id: Ib3e047bef591574154d5656db69e1609aaf30a4a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/547877
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>