Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GOEXPERIMENT=rangefunc #1494

Closed
tamayika opened this issue Feb 9, 2024 · 6 comments
Closed

Support GOEXPERIMENT=rangefunc #1494

tamayika opened this issue Feb 9, 2024 · 6 comments
Labels
started Issues we've started working on

Comments

@tamayika
Copy link

tamayika commented Feb 9, 2024

Currently, staticcheck can not analyze and panic for range iter with GOEXPERIMENT=rangefunc

package main

import (
	"iter"
)

func main() {
	var (
		iter iter.Seq[int]
	)
	for _ = range iter {

	}
}

Stacktrace

panic: Cannot range over: func(yield func(int) bool)

goroutine 140 [running]:
honnef.co/go/tools/go/ir.(*builder).rangeStmt(0xc000483a60, 0xc000598000, 0xc000359da0, 0x0, {0xaa09d0, 0xc000359da0})
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2214 +0x894
honnef.co/go/tools/go/ir.(*builder).stmt(0xc000483a60, 0xc000598000, {0xaa25c0?, 0xc000359da0?})
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2427 +0x20a
honnef.co/go/tools/go/ir.(*builder).stmtList(...)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:847
honnef.co/go/tools/go/ir.(*builder).stmt(0xc000483a60, 0xc000598000, {0xaa2410?, 0xc000283980?})
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2385 +0x1447
honnef.co/go/tools/go/ir.(*builder).buildFunction(0xc000483a60, 0xc000598000)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2497 +0x417
honnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0xc00033da60, 0xc00019cf30, 0xc000283b60)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2534 +0x189
honnef.co/go/tools/go/ir.(*Package).build(0xc00019cf30)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2638 +0xb46
sync.(*Once).doSlow(0xc0003ce460?, 0xc000359c80?)
        C:/Program Files/Go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
        C:/Program Files/Go/src/sync/once.go:65
honnef.co/go/tools/go/ir.(*Package).Build(...)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/go/ir/builder.go:2556
honnef.co/go/tools/internal/passes/buildir.run(0xc0002ffe10)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/internal/passes/buildir/buildir.go:86 +0x1b1
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc000458420, {0xaa4de8?, 0xc00044a140})
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/lintcmd/runner/runner.go:992 +0x71b
honnef.co/go/tools/lintcmd/runner.genericHandle({0xaa4de8, 0xc00044a140}, {0xaa4de8?, 0xc00044a000?}, 0xc00043c360, 0xc0001e5ac0, 0xc000419d50)
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/lintcmd/runner/runner.go:817 +0x11f
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers in goroutine 136
        C:/Users/Owner/go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20231215165614-a367d57f6820/lintcmd/runner/runner.go:1061 +0x6a6
@tamayika tamayika added the needs-triage Newly filed issue that needs triage label Feb 9, 2024
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Feb 9, 2024
@timothy-king
Copy link
Contributor

cc'ed @dominikh on go.dev/cl/555075.

@dominikh
Copy link
Owner

dominikh commented Feb 9, 2024

I don't think Staticcheck will support ranging over functions until the feature is no longer experimental. I'd like to wait for the semantics to be finalized first.

@pomo-mondreganto
Copy link

I believe it's worth noticing that the lack of support for rangefunc in staticcheck effectively blocks a lot of projects from using and experimenting with the iterators, as their CI pipelines will fail.

@ianlancetaylor
Copy link

Just a note that rangefunc is no longer experimental. It's now part of the main branch of Go development, though not yet released.

gopherbot pushed a commit to golang/tools that referenced this issue May 8, 2024
This change disables analyzers that cannot yet safely process
go1.23 range-over-func statements, including buildssa and buildir.
(This is done by poking in an additional Analyzer.Requires edge
on a new temporary analyzer that fails when it sees a range-over-func.)

We plan to revert this change when ssa and ir support the new feature,
but this CL will unblock uses of it in the standard library which
would otherwise cause gopls' tests to crash.

Updates golang/go#67237
Updates dominikh/go-tools#1494

Change-Id: Ibed2a88da94fb84234b4410b6bc7562a493287ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/583778
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopherbot pushed a commit to golang/tools that referenced this issue May 8, 2024
Until staticcheck supports range-over-func, gopls won't attempt
to run it on packages that use range-over-func, which is about to
be nearly all packages. Our existing tests will not work.
So, disable them for now.

Updates dominikh/go-tools#1494
Updates golang/go#67262

Change-Id: Ia498b6122cbb7d3797d5d552acbbf0b3dc736eb9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/584395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
@dominikh dominikh added the started Issues we've started working on label May 16, 2024
@fzipp
Copy link

fzipp commented May 20, 2024

I still get a panic for a project that uses rangefunc. Apparently there is a unhandled switch case in SA4004.

panic: internal error: unhandled case *types.Signature

goroutine 249 [running]:
honnef.co/go/tools/analysis/lint.ExhaustiveTypeSwitch(...)
	go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20240520180541-dcae280a5e87/analysis/lint/lint.go:257
honnef.co/go/tools/staticcheck/sa4004.run.func1.2.1(0x14000e8c8e8)
	go/pkg/mod/honnef.co/go/tools@v0.5.0-0.dev.0.20240520180541-dcae280a5e87/staticcheck/sa4004/sa4004.go:82 +0x130

lint.ExhaustiveTypeSwitch(term.Type().Underlying())

dominikh added a commit that referenced this issue May 20, 2024
@dominikh
Copy link
Owner

@fzipp should be fixed now.

gopherbot pushed a commit to golang/tools that referenced this issue Oct 29, 2024
Also: remove t.Skips related to its types.Alias support,
which is done (dominikh/go-tools#1523).

A follow-up change will revert the workaround for missing
buildir support for range-over-func (dominikh/go-tools#1494),
which is also done.

Change-Id: Ic3dff1e2d9616bc12d0ee2c98e81ca747491c0cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586076
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
started Issues we've started working on
Projects
None yet
Development

No branches or pull requests

6 participants