-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: noisy results for the undeclaredname analyzer in code with parse errors #59888
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
Comments
The underlying issue here is poor error recovery in go/parser; see #58833 Running the analyzer only in the presence of zero parse errors, or a small number, or a set of errors whose locations suggest a narrow "blast radius", seems like a good practical step. |
I must be missing something, because every time I say this nobody bites, but I'm going to say it again for the record :) I don't understand why the type checking in the analyzer behaves differently than the type checking gopls does for itself. Aren't they doing essentially the exact same thing? How is the analyzer seeing errors syntactically earlier in the file than the gopls type check run? (A wild guess: is the file being fixed and the analyzers run on the original content?) |
@heschi why do you think the analyzer type checker is behaving differently? This seems clearly to me like a bug introduced when we refactored analysis: we now run analyzers in the presence of parse errors, when we didn't before.
They both use the same parsing logic. |
Er, because the analyzer is reporting a bazillion errors and the "compiler" source only has one...no? Maybe this is the part I'm missing. |
What's happening here is:
The ultimate fix is in the parser, but we could also do one or more of
|
This is a type error analyzer. We don't show type errors when there are parse errors, but we are running analysis, now. That's why these errors are showing up with 'undeclaredname' source, rather than 'compiler' source. |
Thanks both, I get it now. I probably wrote the code that's claiming the errors. Sorry :) |
@adonovan I think the problem is slightly more subtle: if we weren't suppressing the type error, the diagnostics would be merged into the 'compiler' diagnostic. But we do suppress the type-checker errors, so there is nothing to merge with. |
Change https://go.dev/cl/492295 mentions this issue: |
Change https://go.dev/cl/492988 mentions this issue: |
Change https://go.dev/cl/493616 mentions this issue: |
This CL contains the result of a relentlessly unsatisfactory several hours trying to migrate the @diag markers to the new framework. Success was achieved for bad_test, generated, generator, noparse, rundespiteerrors, undeclared. Some trickier cases remain. Observations: - tests without go.mod files result in packages named after the absolute directory path. Is this intentional? - the new @diag markers ignore the kind and severity fields. Should we restore them? - new @diag markers are quite particular about ranges. - IIUC, the (old) no_diagnostics special case was unnecessary since the framework checks got=want not got>want. Deleted. This was supposed to be an easy preparatory step before fixing the issue below. Updates golang/go#59888 Change-Id: I5cd9c37804f1fd627186c03f5b5d4c24d336a285 Reviewed-on: https://go-review.googlesource.com/c/tools/+/492988 Run-TryBot: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
Reported by @heschi: the new analysis driver in [email protected] results in very noisy analysis for code that contains parse errors, due to the undeclaredname analyzer.

We should not run this analyzer (or any analyzer, AFAICT) if there are parse errors.
CC @adonovan
The text was updated successfully, but these errors were encountered: