-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/cmd/stringer cannot run on a file containing imports #52710
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
Comments
I tried to reproduce this, including with the latest version of
and got some errors that were even more mystifying
but there is no "GO"-anything in my environment, nor is there any mention of "ssa" and the error persisted after |
@golang/tools-team can you give this a look? |
Hi, can you please try |
@findleyr I've just tried with both
Even more interesting, I've cloned the From my $ pushd ../go-tools/cmd/stringer/; go build stringer.go; popd; ../go-tools/cmd/stringer/stringer -type=Pill
$ head -n 1 pill_string.go
// Code generated by "stringer -type=Pill"; DO NOT EDIT. This is reaching my limit of go knowledge... I don't understand why the version of
This all seems rather confusing but I hope someone can make sense of it. I'm happy to help debug further if needed. |
I can't reproduce. How are you installing stringer? Heres what I've done:
i.e. with both the go1.18 beta and a recent go1.19 build, installing the latest version of stringer works fine. |
@0xjac output of |
@seankhliao thanks for your comment, I am not sure why I believe this might have been user error on my part, where I've checked old versions and if I downgrade to With the latest version (
For me this is solved, with my apology for anyone's time being wasted and a special thanks to @seankhliao who made me realize where I got it wrong. 😉 The issue of @dr2chase remains however. But I can't reproduce it. As I started this I am happy to help solve it. @dr2chase did you put the |
Closing as I think the issue @dr2chase is encountering is a separate problem, perhaps related to his environment. |
go version 1.18.5 success but 1.20 has the same error |
I can't reproduce the problem at 1.20 or at tip:
@AdwindOne Is your go.mod file valid? Can you provide the output of |
Also update stringer version, as I was getting this error with the current version for some reason: golang/go#52710
Also update stringer version, as I was getting this error with the current version for some reason: golang/go#52710
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, and with all available versions of
golang.org/x/tools
fromv0.1.0
tov.0.1.10
included.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
stringer
fails to generate aString
method for a type located in a file which contains (unrelated) valid imports.Consider the following
pill.go
file taken from thestringer
documentation, with an extra sillyPrint
function whose sole purpose here is to add an import statement (fmt
):This needs to be placed in a go module, the simplest reproducible example is to put the file above alongside a simple
go.mod
file in apill
directory such as:Simply run the
stringer
command as documented:What did you expect to see?
A correctly generated file:
pill_string.go
which contains the implementation of theString
method for the typePill
defined in the filepill.go
(above) as per the stringer documentation.What did you see instead?
When running the command on the file above, no
pill_string.go
file is generated. Instead we get the following error message:stringer: internal error: package "fmt" without types was imported from "pill"
The text was updated successfully, but these errors were encountered: