Closed rjoleary closed 6 years ago
Playing around with ineffassign
some more, I came up with something more general:
package main
func main() {
x := 0
x = 1
y := 42
y = 2
z := int64(0)
z = 3
_, _, _ = x, y, z
}
The analysis gives:
main.go:7:2: ineffectual assignment to y
main.go:10:2: ineffectual assignment to z
It appears ineffassign
treats the integer literal 0
as a special case. Perhaps int64(0)
should also be a special case along with other integer literals constants for 0
?
Thanks for the report, this is now fixed. To avoid false positives, the tool now treats any potential conversion of zero as a zero initializer. Without type information, it can't distinguish conversions from function or method calls, but better to err on this side than to report false positives.
Encountered this in some real code. This is the minimal repro:
The analysis gives:
However, without the declaration of
y
on that line, the code will not compile. The assignment is necessary to declarey
.