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

x/tools/cmd/stringer: generate failed when use generic in specific form #52482

Closed
loggerhead opened this issue Apr 22, 2022 · 5 comments
Closed
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@loggerhead
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.18.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tyrionlong/Library/Caches/go-build"
GOENV="/Users/tyrionlong/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tyrionlong/go/pkg/mod"
GONOPROXY="code.byted.org"
GONOSUMDB="code.byted.org"
GOOS="darwin"
GOPATH="/Users/tyrionlong/go"
GOPRIVATE="code.byted.org"
GOPROXY="goproxy.cn"
GOROOT="/usr/local/Cellar/go/1.18.1/libexec"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18.1/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/tyrionlong/Downloads/foo/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cm/frs084514z15xs9r7hn3nmzmzzp83s/T/go-build1112305840=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I want to use stringer to generate String() for enums, but I found specific use case of generic will cause it failed.

$ tree
.
├── a
│   └── a.go
├── b
│   └── b.go
├── c
│   └── c.go
├── go.mod
├── go.sum
└── main.go

3 directories, 6 files

$ go generate foo/a
stringer: Unexpected package creation during export data loading
a/a.go:7: running "stringer": exit status 1
package a

import (
    "foo/b"
)

//go:generate stringer -type=Bar
type Bar int

const FooBar Bar = iota

func A() {
    b.B()
}
package b

import (
    "foo/c"
)

func B() {
    c.C[string]()
}
package c

// If `C` don't return with type `T`, `stringer` will work as expected.
func C[T any]() T {
    var t T
    return t
}
package main

import "foo/a"

func main() {
    a.A()
}

What did you expect to see?

go generate foo/a success.

What did you see instead?

$ go generate foo/a
stringer: Unexpected package creation during export data loading
a/a.go:7: running "stringer": exit status 1
@loggerhead loggerhead changed the title affected/package: x/tools/cmd/stringer: generate failed when use generic in specific form Apr 22, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 22, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 22, 2022
@thanm
Copy link
Contributor

thanm commented Apr 22, 2022

What version/vintage is your stringer command? Could you please post the output from

 go version `which stringer`

Thanks.

@thanm thanm added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 22, 2022
@loggerhead
Copy link
Author

@thanm

$ go version `which stringer`
/Users/tyrionlong/go/bin/stringer: go1.18

@ZekeLu
Copy link
Contributor

ZekeLu commented Apr 24, 2022

@loggerhead I think thanm meant to say

go version -m `which stringer`

The -m flag causes go version to print each executable's embedded module version information, when available.

@loggerhead
Copy link
Author

@ZekeLu @thanm ok, below is output:

/Users/tyrionlong/go/bin/stringer: go1.18.1
	path	golang.org/x/tools/cmd/stringer
	mod	golang.org/x/tools	v0.1.10	h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
	dep	golang.org/x/mod	v0.6.0-dev.0.20220106191415-9b9b3d81d5e3	h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
	dep	golang.org/x/sys	v0.0.0-20211019181941-9d821ace8654	h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
	dep	golang.org/x/xerrors	v0.0.0-20200804184101-5ec99f83aff1	h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
	build	-compiler=gc
	build	CGO_ENABLED=1
	build	CGO_CFLAGS=
	build	CGO_CPPFLAGS=
	build	CGO_CXXFLAGS=
	build	CGO_LDFLAGS=
	build	GOARCH=amd64
	build	GOOS=darwin
	build	GOAMD64=v1

I found if I install master branch of stringer, the problem is gone

@ZekeLu
Copy link
Contributor

ZekeLu commented Apr 24, 2022

@loggerhead 👍

A bisect shows that this issue is fixed by golang/tools@afc6aad. And this issue is a duplicate of #51629. So I think this issue can be closed now.

@golang golang locked and limited conversation to collaborators Apr 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants