x/tools/go/analysis/passes/lostcancel: incorrect warning about context leak using defer #58850
Labels
FrozenDueToAge
gopls
Issues related to the Go language server, gopls.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
gopls version
go env
What did you do?
Edit this source code:
You will be warned that:
warning: this return statement may be reached without using the cancel var defined on line X
warning: the cancel function is not used on all paths (possible context leak)
However, it is evident that the cancel function is used on all paths. The analysis is not correctly understanding how the deferred cancellation closure will interact with the return.
I encountered this first on a more sophisticated example:
Thanks to @dominikh for helping me build to smaller reproducer.
What did you expect to see?
No warnings, as this code is correct and will cancel the context on all return paths.
What did you see instead?
Warnings.
Editor and settings
I use
kakoune
withkak-lsp
runninggopls
. I use the defaultkak-lsp
settings.Logs
I suspect that this issue is not a result of editor interaction, but of an assumption within the analysis code, so my logs won't be of much help.
The text was updated successfully, but these errors were encountered: