Skip to content

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

@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

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions