gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
394 stars 22 forks source link

False positive #2 #32

Closed leonklingele closed 5 years ago

leonklingele commented 5 years ago

While scanning the Go source, this tool reports the following lines as an ineffectual assignment to v:

This is not the case as the code is testing runtime finalizers.

Full warnings:

runtime/mfinal_test.go:60:4:warning: ineffectual assignment to v (ineffassign)
runtime/mfinal_test.go:98:3:warning: ineffectual assignment to v (ineffassign)

and

runtime/stack_test.go:126:4:warning: ineffectual assignment to s (ineffassign)
gordonklaus commented 5 years ago

Have you tried removing the reported lines? I think the tests will still pass, because since 1.11 (or earlier?) Go tracks object lifetimes more intelligently than it used to. It will free memory even before a variable referencing it goes out of scope if it sees that the variable is no longer used.

leonklingele commented 5 years ago

They still pass after removing the v = nil assignment! Thanks for helping and sorry for the interruption :)