Skip to content

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

Closed

Description

@dominikh

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions