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
cmd/gofmt: doesn't simplify slices if there is a dot import #15153
Comments
/cc @griesemer |
@dominikh You're absolutely correct. In fact, even w/o the dot-import we actually can't be certain whether So in some sense this was always wrong, but in practice, nobody in his/her right mind is going to declare a I'm not sure how I got to this code - for sure it's pretty old code. Would need to track down the history of that line to figure it out. Let's blame it on lack of coffee. Fix coming shortly. |
Great, thanks. P.S.: Anyone know where the description of the issue went? It certainly wasn't empty earlier :-) |
@dominikh No idea what happened here - I certainly didn't touch it. Hmm... |
CL https://golang.org/cl/21613 mentions this issue. |
I've restored the description… let's hope GitHub doesn't eat it again. |
btw origin of the code: |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.6 linux/amd64
What operating system and processor architecture are you using (go env)?
/
What did you do?
Run gofmt -s on http://play.golang.org/p/9NhvjR24S1
What did you expect to see?
I expected s[:len(s)] to be simplified to s{;}
What did you see instead?
It wasn't simplified.
gofmt has a special check for dot imports and refuses to simplify slices in that case, claiming that it's impossible to know whether len is referring to the built-in function or not. I don't see how that could be true. Even a dot import will only pull in exported identifiers from a package, and no exported identifier can be called "len". Am I missing something here?
The text was updated successfully, but these errors were encountered: