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

cmd/gofmt: nonidempotent format of expression #8021

Closed
dvyukov opened this issue May 18, 2014 · 7 comments
Closed

cmd/gofmt: nonidempotent format of expression #8021

dvyukov opened this issue May 18, 2014 · 7 comments
Assignees
Milestone

Comments

@dvyukov
Copy link
Member

@dvyukov dvyukov commented May 18, 2014

go version devel +386c6757d94c Sat May 17 00:06:56 2014 +0000 + darwin/amd64

source is:
package main
func main() {
    _ = ([]bool{})[([]int{})[((1) + (((((1) + (((((((1) * (((((1) + (1))) + (1))))) + (1))) * (1))))) + (1))))]]
}

The following line:
_ = ([]bool{})[([]int{})[((1) + (((((1) + (((((((1) * (((((1) + (1))) + (1))))) + (1)))
* (1))))) + (1))))]]
transforms to the following after first gofmt:
_ = ([]bool{})[([]int{})[((1)+(((1) + ((((1) * (((1) + (1)) + (1))) + (1)) * (1))) +
(1)))]]
and to the following after second gofmt:
_ = ([]bool{})[([]int{})[((1)+(((1)+((((1)*(((1)+(1))+(1)))+(1))*(1)))+(1)))]]

Second gofmt must not change source.
@dvyukov
Copy link
Member Author

@dvyukov dvyukov commented May 18, 2014

Comment 1:

I would appreciate a fix asap. I can't search for other bugs as this one happens very
frequently.
@griesemer
Copy link
Contributor

@griesemer griesemer commented May 18, 2014

Comment 2:

Owner changed to @griesemer.

Status changed to Accepted.

@griesemer
Copy link
Contributor

@griesemer griesemer commented May 19, 2014

Comment 3:

Tentative fix: https://golang.org/cl/92380051
You can patch this CL and it will fix your specific problem. It doesn't impact the std
lib but it may impact other code. Also, I like to understand the consequences better and
perhaps be a bit more aggressive with parentheses removal. Not crucial for 1.3.

Labels changed: added release-go1.4.

Status changed to Started.

@dvyukov
Copy link
Member Author

@dvyukov dvyukov commented May 20, 2014

Comment 4:

The patch works for me. I have not seen any other re-formats after applying this patch.
Thanks for the quick fix, Robert!
@dvyukov
Copy link
Member Author

@dvyukov dvyukov commented May 20, 2014

Comment 5:

Labels changed: added repo-main.

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 11, 2014

Comment 6:

CL https://golang.org/cl/142020043 mentions this issue.
@griesemer
Copy link
Contributor

@griesemer griesemer commented Sep 12, 2014

Comment 7:

This issue was closed by revision a14c1c9.

Status changed to Fixed.

@dvyukov dvyukov added fixed labels Sep 12, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
…nt around an expr

No impact on formatting on our repos.

Fixes golang#8021.

LGTM=adonovan
R=adonovan, dvyukov
CC=golang-codereviews
https://golang.org/cl/142020043
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
…nt around an expr

No impact on formatting on our repos.

Fixes golang#8021.

LGTM=adonovan
R=adonovan, dvyukov
CC=golang-codereviews
https://golang.org/cl/142020043
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
…nt around an expr

No impact on formatting on our repos.

Fixes golang#8021.

LGTM=adonovan
R=adonovan, dvyukov
CC=golang-codereviews
https://golang.org/cl/142020043
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.