8000 S1005 flags `_ = <-errCh`, which errcheck v1.30.0 requires for a discarded error receive · Issue #1844 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content

S1005 flags _ = <-errCh, which errcheck v1.30.0 requires for a discarded error receive #1844

Open

Description

@fabifont
  • staticcheck -version: staticcheck 2026.2.2 (0.8.2)
  • staticcheck -debug.version: staticcheck 2026.2.2 (0.8.2), compiled with go1.27.1, main module honnef.co/go/tools@v0.8.2
  • go version: go version go1.27.1 linux/amd64
  • go env: GOOS='linux' GOARCH='amd64' GOVERSION='go1.27.1' GOFLAGS='' CGO_ENABLED='1' GOTOOLCHAIN='auto'
  • Command: staticcheck ./... on the file below
  • Output: main.go:14:2: unnecessary assignment to the blank identifier (S1005)
package main

import "errors"

func work(errCh chan error) {
	go func() { errCh <- errors.New("done") }()
}

func receiveBare(errCh chan error) {
	<-errCh
}

func receiveBlank(errCh chan error) {
	_ = <-errCh
}

func main() {
	errCh := make(chan error, 1)
	work(errCh)
	receiveBare(errCh)
	work(errCh)
	receiveBlank(errCh)
}

Since errcheck v1.30.0 (2026-10-09, kisielk/errcheck#288), a bare receive from a channel whose element type implements error is reported as an unchecked error, so errcheck ./... on the same file reports main.go:10:2: <-errCh. errcheck accepts _ = <-errCh as the explicit discard, the same way it accepts _ = f(). S1005 then rewrites _ = <-errCh back into <-errCh (it is the example in the check's documentation, and s1005.go matches (Ident "_") _ recv@(UnaryExpr "<-" _)), so a project that runs both linters, as golangci-lint does by default, has no spelling of "receive and discard this error" that passes.

The code is fine: the blank assignment documents that the received value is an error dropped on purpose, which is what errcheck asks for. Could S1005 leave _ = <-ch alone when the channel's element type implements error? The rewrite would stay for channels of other types, where the blank identifier carries no information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0