Repository navigation
x/tools/gopls: Incorrect warnings that yield maybe called again #80814
Copy link
Copy link
Open
Labels
ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.
Milestone
Description
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 falseyield 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.
Activity
madelinekalil commentedon Aug 13, 2026
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