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/imports: packages used only in function signatures are not auto-imported #20442

Closed
odeke-em opened this issue May 20, 2017 · 4 comments
Closed

Comments

@odeke-em
Copy link
Member

Please answer these questions before submitting your issue. Thanks!

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

Go1.8 running on the playground at https://play.golang.org/

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

Irrelevant

What did you do?

screen shot 2017-05-20 at 1 13 20 pm

  • Hit format to perform the auto-importing then run

screen shot 2017-05-20 at 1 17 29 pm

What did you expect to see?

All packages auto-imported including "reflect" and a successful run

What did you see instead?

Notice that it didn't import "reflect" as that package in used only in the function signature, but successfully imported the rest of the packages, thus it failed to compile and I had to manually go import "reflect".

@gopherbot gopherbot added this to the Unreleased milestone May 20, 2017
@josharian josharian changed the title x/tools/playground: packages used only in function signatures are not auto-imported x/tools/imports: packages used only in function signatures are not auto-imported May 20, 2017
@mvdan
Copy link
Member

mvdan commented May 22, 2017

I just ran goimports -l -w on that code and it works fine, on x/tools bf4b54dc687c73b6ef63de8b8abf0ad3951e3edc and go version devel +495f55d27d Fri May 19 18:11:51 2017 +0000 linux/amd64.

I tried with a goimports built with Go 1.8.1, but still no luck. Maybe it's the playground having an old goimports?

@odeke-em
Copy link
Member Author

Interesting, /cc @broady

@mvdan
Copy link
Member

mvdan commented May 24, 2017

Smaller repro: https://play.golang.org/p/t10VJFbmgC

Note that if you make the argument a reflect.Value it suddenly starts working. Both types have been in Go since 1.0, so I'm not sure why that would be.

@broady any information on how goimports/imports is being run in the Playground, or what version of it is being used?

@agnivade
Copy link
Contributor

Seems to be working now. Closing.

@golang golang locked and limited conversation to collaborators Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants