Skip to content

x/tools/gopls: Incorrect warnings that yield maybe called again #80814

Open

Description

@kendfss

Go version

go version go1.26.5 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='/bin/clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/kendfss/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/kendfss/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2429080807=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/kendfss/gitclone/clones/kendfss/cross/go.mod'
GOMODCACHE='/home/kendfss/go/pkg/mod'
GONOPROXY='github.com/kendfss'
GONOSUMDB='github.com/kendfss'
GOOS='linux'
GOPATH='/home/kendfss/go'
GOPRIVATE='github.com/kendfss'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/kendfss/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.5'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

func wrap[T any](t T, str string, args ...any) T {
	fmt.Fprintln(os.Stderr, str, args....)
	return t
}

func i(n uint) iter.Seq[uint] {
	return func(yield func(uint)bool) {
		for n > 0 {
			if !wrap(yield(n), "some context/location specific string") {
				return
			}
			n--
		}
	}
}

What did you see happen?

Depending on where the wrap function is used (and sorry, I currently lack the words to distinguish between the respective causes), one of the following diagnostics:

  • yield may be called again after returning false
  • yield may be called again (on L331) after returning false

What did you expect to see?

Usage of boolean algebraic principles that influence suggestions for things like deMorgan's law and redundant if statements being applied to conclude that the wrap function's returned value doesn't disagree with yield's.

This picks up, more or less, where #70598 leaves off.

Activity

  1. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    goplsIssues related to the Go language server, gopls.
    on Aug 10, 2026
  2. added this to the Unreleased milestone on Aug 10, 2026
  3. assigned and unassigned on Aug 13, 2026
  4. madelinekalil commented on Aug 13, 2026

    @madelinekalil
    Contributor

    Thanks for the bug report! I believe this would be quite complicated to implement, so we won't be prioritizing it. There is a reason that this is a "may" analysis rather than "must". See the comment here for a longer explanation: https://github.com/golang/tools/blob/3c18a2d526461d00b70b0eab33e0b0fc54e52a55/gopls/internal/analysis/yield/yield.go#L61

  5. removed their assignment
    on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions