-
Notifications
You must be signed in to change notification settings - Fork 4
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
False positive when a loop var is exported, directly followed by break #14
Comments
📝 to generalize 💭 What kind of structure is a alignment directly followed by a break? result = &hay
(...something no mattered...)
break NOTE: -> there's no problem. no problem casesdirectly followed by break:
there's steps that never
breaks on parent branch:
diagnosticsbreaks sometimes
Cost to probe the diagnostics
How to do
WorryMaybe to resolve this, exportloopref will be slow (about 3 times) |
To make it simple: First pass
Second passFor each candidates:
|
@kyoh86 thank you for looking into this! I would already be very happy if the case of "pointer assignment directly followed by break/return" would work. |
Your requirement is so simple. If you have an idea, please give me a pull request. |
Exporting pointers for loop variables can create very hard to debug bug. Contrary to what can think, the `:=` assignment in the range loop does not create a new local variable on each iteration, see the following Go Language specification extract. "The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=). In this case their types are set to the types of the respective iteration values and their scope is the block of the "for" statement; they are re-used in each iteration. If the iteration variables are declared outside the "for" statement, after execution their values will be those of the last iteration." Creating a local variable fix this issue and allocate new memory each time making it possible to export the pointer. When immediatly using break after, it's okay but linter is not capable of detecting that because of perf slowdown, see kyoh86/exportloopref#14. See more info: - https://github.com/kyoh86/exportloopref - https://medium.com/swlh/use-pointer-of-for-range-loop-variable-in-go-3d3481f7ffc9 Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Exporting pointers for loop variables can create very hard to debug bug. Contrary to what can think, the `:=` assignment in the range loop does not create a new local variable on each iteration, see the following Go Language specification extract. "The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=). In this case their types are set to the types of the respective iteration values and their scope is the block of the "for" statement; they are re-used in each iteration. If the iteration variables are declared outside the "for" statement, after execution their values will be those of the last iteration." Creating a local variable fix this issue and allocate new memory each time making it possible to export the pointer. When immediately using break after, it's okay but linter is not capable of detecting that because of perf slowdown, see kyoh86/exportloopref#14. See more info: - https://github.com/kyoh86/exportloopref - https://medium.com/swlh/use-pointer-of-for-range-loop-variable-in-go-3d3481f7ffc9 Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Exporting pointers for loop variables can create very hard to debug bug. Contrary to what can think, the `:=` assignment in the range loop does not create a new local variable on each iteration, see the following Go Language specification extract. "The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=). In this case their types are set to the types of the respective iteration values and their scope is the block of the "for" statement; they are re-used in each iteration. If the iteration variables are declared outside the "for" statement, after execution their values will be those of the last iteration." Creating a local variable fix this issue and allocate new memory each time making it possible to export the pointer. When immediately using break after, it's okay but linter is not capable of detecting that because of perf slowdown, see kyoh86/exportloopref#14. See more info: - https://github.com/kyoh86/exportloopref - https://medium.com/swlh/use-pointer-of-for-range-loop-variable-in-go-3d3481f7ffc9 Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Exporting pointers for loop variables can create very hard to debug bug. Contrary to what can think, the `:=` assignment in the range loop does not create a new local variable on each iteration, see the following Go Language specification extract. "The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=). In this case their types are set to the types of the respective iteration values and their scope is the block of the "for" statement; they are re-used in each iteration. If the iteration variables are declared outside the "for" statement, after execution their values will be those of the last iteration." Creating a local variable fix this issue and allocate new memory each time making it possible to export the pointer. When immediately using break after, it's okay but linter is not capable of detecting that because of perf slowdown, see kyoh86/exportloopref#14. See more info: - https://github.com/kyoh86/exportloopref - https://medium.com/swlh/use-pointer-of-for-range-loop-variable-in-go-3d3481f7ffc9 Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Exporting pointers for loop variables can create very hard to debug bug. Contrary to what can think, the `:=` assignment in the range loop does not create a new local variable on each iteration, see the following Go Language specification extract. "The iteration variables may be declared by the “range” clause using a form of short variable declaration (:=). In this case their types are set to the types of the respective iteration values and their scope is the block of the "for" statement; they are re-used in each iteration. If the iteration variables are declared outside the "for" statement, after execution their values will be those of the last iteration." Creating a local variable fix this issue and allocate new memory each time making it possible to export the pointer. When immediately using break after, it's okay but linter is not capable of detecting that because of perf slowdown, see kyoh86/exportloopref#14. See more info: - https://github.com/kyoh86/exportloopref - https://medium.com/swlh/use-pointer-of-for-range-loop-variable-in-go-3d3481f7ffc9 Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
In Go 1.22, it is not a problem |
exportloopref complains about something like this, even though it is valid:
The text was updated successfully, but these errors were encountered: