Skip to content

x/tools/cmd/stringer: internal error when importing go packages on go1.18 for Linux  #51924

Closed
@avislash

Description

@avislash

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

Activity

seankhliao

seankhliao commented on Mar 24, 2022

@seankhliao
Member

what version of stringer?

mknyszek

mknyszek commented on Mar 24, 2022

@mknyszek
Contributor

Is this issue new in Go 1.18?

changed the title [-]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 [/+] on Mar 24, 2022
added
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Mar 24, 2022
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
and removed
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Mar 24, 2022
added this to the Unreleased milestone on Mar 24, 2022
modified the milestones: Unreleased, Backlog on Mar 24, 2022
mknyszek

mknyszek commented on Mar 24, 2022

@mknyszek
Contributor

CC @golang/tools-team

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
on Mar 24, 2022
modified the milestones: Backlog, Unreleased on Mar 24, 2022
added
WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.
on Mar 24, 2022
avislash

avislash commented on Mar 24, 2022

@avislash
Author

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 using go 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.

locked and limited conversation to collaborators on Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mknyszek@gopherbot@seankhliao@avislash

        Issue actions

          x/tools/cmd/stringer: internal error when importing go packages on go1.18 for Linux · Issue #51924 · golang/go