-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modifies-value-receiver: miss modification by setting something in a slice #1116
Comments
Hi @ccoVeille, could you please elaborate on what the problem is? The fact that Foo refers to the first position of a potentially not initialized slice? (revive can't do too much about that) The rule spots assignments to a by value receiver to prevent the error of modifying an "ephemeral" copy of the struct in the belief that the modification is made on the "persistent" version. In the example you provide, the "persistent" slice content is actually modified by Foo |
It's not about that
Yes. A slice that is a copy of Foo
But Foo is passed without a pointer. So a.lst[0] is not set to "whatever" outside this method. Please take a look at Incr() method in the example provided on #109 It's the same logic, no? I mean outside the method the counter is not incremented. The current code detect if you set a value of the struct and if you return nothing, no? I might be simply missing something, or maybe everything. |
The slice content is actually modified "globally": https://go.dev/play/p/-K_b2r9wrUm |
Indeed, but replacing the value, no. https://go.dev/play/p/dQMftzHYzT- I think I faced this once. It looks like very odd, when you face it. |
Somehow related to
++
/--
#1109This is not detected
Here we have to assume that lst was populated before calling Foo
The text was updated successfully, but these errors were encountered: