Open
Description
The following code
func f(i interface{}) *T {
x, ok := i.(*T)
if !ok {
x := new(T)
x.f = 0
}
return x
}
compiles without errors even though it is obviously incorrect: Inside the block of the if
statement, the :=
operator should have been =
instead. The compiler doesn't complain because the assignment to x.f
counts as use of x
.
Arguably, assignments to fields/elements of composite type variables shouldn't be counted as uses. Their effect is lost if the variable itself is never used and they may hide the fact that the variable is not used.
(This was the underlying cause for #20789.)