-
Notifications
You must be signed in to change notification settings - Fork 571
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
WIP: New inspection: Obtaining address of a for loop variable #2422
base: master
Are you sure you want to change the base?
WIP: New inspection: Obtaining address of a for loop variable #2422
Conversation
58d00af
to
7845df6
Compare
Not sure that it's necessary inspection. As far as I understand it will compain about following code: package main
import "fmt"
func doSomethingWithPointer(pointer *int) {
fmt.Println(*pointer)
}
func main() {
for _, i := range []int{1, 2, 3} {
doSomethingWithPointer(&i)
}
} but in my opinion it's more or less valid case and its output looks logical to me:
|
Your example is legit. But it can be a problem if a pointer is stored somewhere. The pointer is the same on each iteration of the loop and it can be a source of hard-to-find bugs. |
My point is that other functions might require pointer-parameters and you have to obtain address in these cases, and I think that IDEA shouldn't complain about it. |
BTW, you can add it and disable by default. |
@zolotov that's true, that's why I asked for opinions on whether this inspection is too loud. So, yes, I can either make it disabled by default, or I can use scripting extensions to have it for myself only. |
Disabled by default inspection looks good to me |
@deadok22 can it be merge now? with disabling by default. If so, please rebase and disable the inspection by default. |
No, I still have a TODO there. |
Please, don't merge it now - it's a work in progress.
Today I've spent about an hour looking for a bug introduced by obtaining address of a for loop variable. This inspection could have helped to avoid that bug, or at the very least, it'd have helped me find it =)
Please, let me know if my vision of the problem is incomplete or if this inspection is too loud.