I encountered this while running unused on rs/zerolog.
% unused ./...
log_test.go:371:3: field l is unused (U1000)
log_test.go:372:3: field p is unused (U1000)
Here is the offending code.
type levelWriter struct {
ops []struct {
l Level
p string
}
}
...but it appears to be used right below.
func (lw *levelWriter) WriteLevel(lvl Level, p []byte) (int, error) {
lw.ops = append(lw.ops, struct {
l Level
p string
}{lvl, string(p)})
return len(p), nil
}
Is unused confused by the anonymous struct?
I'm using the latest master commit (Feb 19, 2018), built with Go 1.10.
It is not used "right below". Merely assigning to the fields does not count as usage if the fields are never being read (either directly, or indirectly via reflection.)
You are right that they are being used, however, via reflect.DeepEqual. I will have to check if this bug is caused by the use of DeepEqual, or by the use of anonymous structs.
https://github.com/dominikh/go-tools/issues/203 would suggest that we are struggling with anonymous types, though. Which isn't surprising; unused is due for a redesign and rewrite.
This should be fixed in master.
Most helpful comment
This should be fixed in master.