-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
SA1026: False positive when func json.Marshaler used as a field #1088
Comments
Interesting. I didn't expect this to work, but apparently the fact you're marshaling |
Further investigation revealed that the check, as implemented, is very naive and doesn't implement addressability, nesting, or the various rules of For the fix we will maintain a modified copy of We may have to do something similar for |
The previous version of SA1026 was very naive. - It didn't take addressability into consideration, leading to false positives. - It didn't cull fields with name conflicts, leading to false positives. - It didn't traverse into nested structures, leading to false negatives. The new check is based on a modified copy of encoding/json that applies all relevant rules. Updates gh-1088
Same as previous commit, but for XML instead of JSON. Because we rely on encoding/xml, we can now flag a plethora of invalid struct tags. Closes gh-1088
The previous version of SA1026 was very naive. - It didn't take addressability into consideration, leading to false positives. - It didn't cull fields with name conflicts, leading to false positives. - It didn't traverse into nested structures, leading to false negatives. The new check is based on a modified copy of encoding/json that applies all relevant rules. Updates gh-1088 (cherry picked from commit 467468a)
The SA1026 check (to check if a
func
orchan
is being marshalled) gives a false positive, when a json.Marshaler is used as a field:When running
staticcheck .
on this, it outputs:But running this program outputs:
showing that this works as expected.
I assume the cause here is that staticcheck looks at the method set of
T
, not of*T
, as that's the type of the field. If I change the method receiver toT
, the error message disappears.staticcheck version:
staticcheck 2021.1.1 (v0.2.1)
'staticcheck -debug.version'
go version:
go version go1.17.1 linux/amd64
Output of 'go env'
The text was updated successfully, but these errors were encountered: