You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't a bug per se, but it's a bug pattern that tools could help with.
Given this code
type T struct {
F *int
}
Let's say you change this exported field F into a private field f plus an exported
accessor, like so:
type T struct {
f *int
}
func (t *T) F() *int { return t.f }
Now you have to rename all references to T.F into T.F(). Mostly you can rely on
compiler errors to help you find what you need to change... but not always. Consider:
if t.F == nil { ... }
Thanks to the new feature whereby t.f evaluates to a method closure, this statement is
still valid after the change, but is now a provably false condition, so the statement
has no effect. This is not what the user intended.
It seems to me that a comparison of f==nil, where f is the name of a method or function,
or an expression that creates a bound function, is almost surely a mistake.
We could make it a compiler error, or we could make go vet report it.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: