Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.18 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Ubuntu 20.04 LTS (Linux ubhold 5.11.0-46-generic #51~20.04.1-Ubuntu SMP Fri Jan 7 06:51:40 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)
NOTE: This works as expected on Mac OS. This only appears to be a problem on Linux and this was working fine before with go1.17.
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/redacted/.cache/go-build" GOENV="/home/redacted/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/redacted/go/pkg/mod" GONOPROXY="github.com/redacted*" GONOSUMDB="github.com/redacted/*" GOOS="linux" GOPATH="/home/redacted/go" GOPRIVATE="github.com/redacted/*" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/lib/go-1.18" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.18/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="/usr/bin/g++-7" CGO_ENABLED="1" GOMOD="/home/redacted/go_tutorial/stringer_is_broke_af/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4289626171=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I tried to use stringer
to auto-generate the Stringer
interface for an enum using go1.18 (installed via APT) on Ubuntu 20.04 LTS.
Using go generate
or just running stringer
on the code below reproduces the error for me
//go:generate stringer -type=Foo -trimprefix Foo
package main
import "fmt"
type Foo uint64
const (
FooZero Foo = iota
FooOne
FooTwo
)
func main() {
var f Foo
fmt.Println(f)
}
If I remove the "fmt" import and instead just use a print() I get no errors.
//go:generate stringer -type=Foo -trimprefix Foo
package main
type Foo uint64
const (
FooZero Foo = iota
FooOne
FooTwo
)
func main() {
var f Foo
print(f)
}
What did you expect to see?
I expected to see a file called foo_string.go that implements a String() method for the Foo enum
What did you see instead?
$ go generate . stringer: internal error: package "fmt" without types was imported from "stringer_is_broke_af" main.go:1: running "stringer": exit status 1
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
seankhliao commentedon Mar 24, 2022
what version of stringer?
mknyszek commentedon Mar 24, 2022
Is this issue new in Go 1.18?
[-]Stringer Internal Error when importing go packages on go1.18 for Linux [/-][+]x/tools/cmd/stringer: internal error when importing go packages on go1.18 for Linux [/+]mknyszek commentedon Mar 24, 2022
CC @golang/tools-team
avislash commentedon Mar 24, 2022
Thanks for the prompt response! I figured out the root issue, it turns out the stringer binary was not being updated when I tried to update to golang.org/x/tools v0.1.10.
I had to blow away stringer in
go/bin/
and then reinstall usinggo install golang.org/x/tools/cmd/stringer@latest
.Once I did this I was able to use
go generate
again.I'm still not really sure why this manifested in Linux and not in Mac OS.