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
Show() has a pointer type receiver, and loop variable m is of type MyInt. In m.Show(), m will be implicitly converted to a pointer ((&m).Show()), thus implicitly creating a reference to the loop variable that are then passed to go/defer function.
This mistake is more subtle than accidentally capturing loop variables with function literals since it's impossible to detect if only looking at the for loop without also checking the receiver type of Show(). So I think this is worth vetting for.
I imagine a implementation of such check would look a lot like loopclosure. And would share a lot of the same logics (such as maybe? the recent #57173). But it isn't technically caused by "closure" so I'm not sure that's the right place to do it.
The text was updated successfully, but these errors were encountered:
Miigon
changed the title
proposal: cmd/vet: references implicitly converted from values being passed to go/defer
proposal: cmd/vet: references implicitly created from loop variables being passed to go/defer
Mar 6, 2023
Consider the following case:
Result:
Show()
has a pointer type receiver, and loop variablem
is of typeMyInt
. Inm.Show()
,m
will be implicitly converted to a pointer ((&m).Show()
), thus implicitly creating a reference to the loop variable that are then passed to go/defer function.This mistake is more subtle than accidentally capturing loop variables with function literals since it's impossible to detect if only looking at the for loop without also checking the receiver type of
Show()
. So I think this is worth vetting for.I imagine a implementation of such check would look a lot like
loopclosure
. And would share a lot of the same logics (such as maybe? the recent #57173). But it isn't technically caused by "closure" so I'm not sure that's the right place to do it.The text was updated successfully, but these errors were encountered: