Skip to content
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

SA9001: false positive in presence of control flow statements #488

Closed
dominikh opened this issue May 19, 2019 · 0 comments
Closed

SA9001: false positive in presence of control flow statements #488

dominikh opened this issue May 19, 2019 · 0 comments

Comments

@dominikh
Copy link
Owner

Neither of these defers should get flagged:

package pkg

func fn() {
	var ch chan int
	for range ch {
		defer println()
		break
	}

	for range ch {
		defer println()
		return
	}
}

But they do get flagged:

/tmp/foo.go:6:3: defers in this range loop won't run unless the channel gets closed (SA9001)
/tmp/foo.go:11:3: defers in this range loop won't run unless the channel gets closed (SA9001)
KarthikNayak added a commit to KarthikNayak/go-tools that referenced this issue Jul 3, 2022
As noted in the PR: dominikh#488,
let's check if there is either a `return` statement or a `break` control
flow when looping over channels. This would reduce false positives.

Add a test for the same as noted in the issue!

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
dominikh pushed a commit that referenced this issue Aug 17, 2023
As noted in issue gh-488, let's check if there is either a 'return' or a
'break' statement when looping over channels.

Add a test for the same as noted in the issue!

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Closes: gh-1298 [via git-merge-pr]
Closes: gh-488
(cherry picked from commit bfa1dc5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant