Skip to content

cmd/compile: go1.27.0 unified export data loses method order, breaking objectpath, crashing staticcheck #81188

Closed

Description

@bradfitz

We just started converting Tailscale's internal codebase to use Go 1.27's generic methods and a few rounds of conversion went well, and then we hit CI failures with staticcheck crashing on us:

panic: runtime error: index out of range [1] with length 1

goroutine 2938 [running]:
honnef.co/go/tools/analysis/facts/nilness.(*Result).Nilness(0x13ab31d515b0, 0x13ab2daf6480, 0x1)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/analysis/facts/nilness/nilness.go:77 +0x10f
honnef.co/go/tools/staticcheck/sa4023.run(0x13ab352e2e00)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/staticcheck/sa4023/sa4023.go:181 +0x6bf
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0x13ab3b1122d0, {0xee2f70?, 0x13ab3b108be0})
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:989 +0x722
honnef.co/go/tools/lintcmd/runner.genericHandle({0xee2f70, 0x13ab3b108be0}, {0xee2f70?, 0x13ab27e12be0?}, 0x13ab382ed6c0, 0x0, 0x13ab3b5594d0)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:814 +0x111
honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers(0x13ab270e68a0, 0x13ab27262b40, 0x13ab36be0280)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:1062 +0x73d
honnef.co/go/tools/lintcmd/runner.(*subrunner).doUncached(0x13ab270e68a0, 0x13ab27262b40)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:717 +0x22d
honnef.co/go/tools/lintcmd/runner.(*subrunner).do(0x13ab270e68a0, {0xee2fb8?, 0x13ab27262b40})
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:574 +0xa72
honnef.co/go/tools/lintcmd/runner.(*Runner).Run.func2({0xee2fb8?, 0x13ab27262b40?})
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:1224 +0x2a
honnef.co/go/tools/lintcmd/runner.genericHandle({0xee2fb8, 0x13ab27262b40}, {0xee2fb8?, 0x13ab28b54120?}, 0x13ab26faa230, 0x13ab272ba158, 0x13ab26fa4700)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:814 +0x111
created by honnef.co/go/tools/lintcmd/runner.(*Runner).Run in goroutine 1
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.0-rc.1/lintcmd/runner/runner.go:1223 +0x41f

I noticed we'd been using an old version (v0.8.0-rc.1) so I figured it might already be fixed in a newer one. I had to put the kids to bed so I told my trusty agent to bump staticcheck and see if that fixes it.

Instead, I came back to my computer and found it made this diagnosis & minimal repro: https://github.com/bradfitz/bug-go127-staticcheck-crash

$ git clone https://github.com/bradfitz/bug-go127-staticcheck-crash.git
$ cd bug-go127-staticcheck-crash
$ go tool staticcheck ./...
panic: runtime error: index out of range [1] with length 1

goroutine 169 [running]:
honnef.co/go/tools/analysis/facts/nilness.(*Result).Nilness(0x3f1e0842a220, 0x3f1e07ea1620, 0x1)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.1/analysis/facts/nilness/nilness.go:77 +0x10f
honnef.co/go/tools/staticcheck/sa4023.run(0x3f1e0873d5e0)
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.1/staticcheck/sa4023/sa4023.go:181 +0x6bf
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0x3f1e08017d70, {0xedfd38?, 0x3f1e0849bc20})
	/home/ubuntu/go/pkg/mod/honnef.co/go/tools@v0.8.1/lintcmd/runner/runner.go:989 +0x722
...

Something seems unhappy in the export data or go/types or their interaction with the new generic methods.

But for now we have to choose between using staticcheck and using generic methods.

/cc @golang/compiler @golang/tools-team @dominikh

Activity

  1. mrkfrmn commented on Aug 28, 2026

    @mrkfrmn
    Contributor

    Related to #61443 and cc @adonovan.

    Generic methods are placed after ordinary methods in the export data. It seems this broke the invariant that export data must preserve method order. Thus, the same objectpath might refer to different methods depending on whether a type with generic methods came from source or export data.

    The obvious solution is to bump the export data version to preserve ordering, but we'd need to either gate the new version on a minor release or wait to do that in Go 1.28, which seems untenable.

  2. adonovan commented on Aug 28, 2026

    @adonovan
    Member

    Thanks for investigating. This is a nice illustration of one of the benefits of no longer using compiler export data in x/tools (#79427). It occurs to me that unitchecker could (indeed should) export type-export data too (not just facts), much like cmd/export does, then the build tool (e.g. go vet) wouldn't need to execute the compiler (or cmd/export in future) at all: it's just a redundant step. Let's discuss when you're back in the office. That's orthogonal to this issue though.

    I think this bug may need a backported patch to cmd/compile in 1.27 since it breaks x/tools/go/packages.

  3. deleted a comment from gopherbot on Aug 28, 2026
  4. adonovan commented on Aug 28, 2026

    @adonovan
    Member

    https://go.dev/cl/824004 is the unitchecker change mentioned above (though it only benefits the next Go release).

  5. gopherbot commented on Aug 28, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/824004 mentions this issue: go/analysis/unitchecker: export type information

  6. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Aug 28, 2026
  7. added this to the Go1.28 milestone on Aug 28, 2026
  8. self-assigned this
    on Sep 1, 2026
  9. adonovan commented on Sep 1, 2026

    @adonovan
    Member

    The obvious solution is to bump the export data version to preserve ordering, but we'd need to either gate the new version on a minor release or wait to do that in Go 1.28, which seems untenable.

    I agree that it can't be fixed without a protocol change as the necessary ordering information is lost. (Tempting though it is, we can't reliably reconstruct the ordering from each method's (filename, line, column) triple, because files are only guaranteed to be presented to the compiler in name order when using go build; other build systems such as Bazel compile files in the order they are enumerated in the BUILD file.)

    So, we'll need to:

    • bump the protocol version so that method index is explicit
    • update the "u" decoder in x/tools
    • release x/tools
    • update the "u" encoder in cmd/compile
    • backport the compiler change and re-release.

    Staticcheck will need to update its x/tools requirement and be re-released so that it will understand the files produced by the fixed compiler (instead of giving a "ureader too old" error).

    Sigh. #79427 cannot come soon enough.

    cc: @griesemer @mrkfrmn @dominikh

  10. gopherbot commented on Sep 1, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/826064 mentions this issue: internal/gcimporter: support V5 unified encoding (method indices)

  11. changed the title [-]go/types: staticcheck started crashing on us with Go 1.27 generic methods[/-] [+]cmd/compile: go1.27.0 unified export data loses method order, breaking objectpath, crashing staticcheck[/+] on Sep 1, 2026
  12. 43 remaining items

  13. mvdan commented on Oct 12, 2026

    @mvdan
    Member

    I'm a little surprised that the upgrade from Go 1.27.1 to 1.27.2 required updating x/tools as well to keep e.g. staticcheck from breaking all of a sudden: dominikh/go-tools#1832

    Typically, updating Go minor (bugfix) versions is very safe to do and does not require any further version updates to keep everything working. This is not the end of the world, but with workflows like https://github.com/actions/setup-go tracking Go 1.27.x, this suddenly broke our CI and it took me a while to figure out what was going on. And the fix is a little cumbersome, as I have to update x/tools across a dozen repos.

    Just my two cents in case this can be done more smoothly next time :) I am not aware of the background of this issue or why the breaking change was necessary in the first place.

  14. adonovan commented on Oct 12, 2026

    @adonovan
    Member

    The problem is that the 1.27 export data discarded vital information, and a change of protocol was required to add it back. The change of protocol required an update in the x/tools reader. I knew it would be disruptive for users of export data, but I couldn't see any alternative route that would have been less disruptive yet still fixed an inevitable crash for which there was no workaround.

    It does suggest we need better test coverage to prevent this kind of thing from happening more often.

  15. added a commit that references this issue on Oct 19, 2026
  16. gopherbot commented on Oct 28, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/855582 mentions this issue: [release-branch.go1.27] cmd/compile: record method indices before encoding a named type

  17. added a commit that references this issue on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions