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)