-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: spurious 'unused write' in package reflect #67684
Comments
I suspect it would be enough for the analyzer to differentiate between implicit field access and explicit field references, bailing out for the latter. That would preserve most of the usefulness and avoid these types of false positives. This looks (naively) like a pretty straightforward fix. Putting in the [email protected] milestone. |
Perhaps the analyzer should just be silent in packages that import |
That was my first thought as well, but there's no reason the cast must be in the same package as the field addr. |
Well, there kind of is: it is very bad form to expose unsafe public API. There could be a constellation of internal packages working together this way, but that may be rare enough to justify the heuristic. |
According to the information available here a significant number of packages import unsafe |
@MikeMitchellWebDev pkg.go.dev reports over 4m importers of fmt, so the number of packages importing unsafe is at most 2-3%, probably more like 1-2%. Skipping this specific heuristic in the presence of unsafe seems acceptable. |
I opened reflect/type.go and gopls started telling me:
This is false. The code for the first two errors is:
What the analyzer doesn't see is that &ch.Type provides access to all of ch.
/cc @rfindley @adonovan
The text was updated successfully, but these errors were encountered: