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

goimports doesn't import packages that have the same name as a local function #21919

Closed
zakkor opened this issue Sep 18, 2017 · 2 comments
Closed

Comments

@zakkor
Copy link

zakkor commented Sep 18, 2017

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

go version go1.9 linux/amd64

Does this issue reproduce with the latest release?

yes

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

ubuntu 16.04 amd64

What did you do?

If you have a function with the same name as a package, goimports won't add that import

package main

func exec() {
}

func os() {
}

func main() {
	if len(os.Args) != 2 {
	}
	cmd := exec.Command("a")
}

What did you expect to see?

the "os" and "os/exec" packages added as imports

What did you see instead?

the "os" and "os/exec" packages not added as imports

@zakkor
Copy link
Author

zakkor commented Sep 18, 2017

nvm this is a compile error, my bad

@zakkor zakkor closed this as completed Sep 18, 2017
@griesemer
Copy link
Contributor

Indeed. You cannot have an imported package have the same name as a package-level entity (function, variable, type, constant).

@golang golang locked and limited conversation to collaborators Sep 18, 2018
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

3 participants