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: breaks channel syntax #10040

Closed
bgeron opened this issue Feb 28, 2015 · 2 comments
Closed

cmd/gofmt: breaks channel syntax #10040

bgeron opened this issue Feb 28, 2015 · 2 comments

Comments

@bgeron
Copy link

bgeron commented Feb 28, 2015

In Go 1.4.1, gofmt reformats chan <-chan int to chan<- chan int. The two are different in the AST, and indeed gofmt can break working source; see http://play.golang.org/p/L9xzobGwob for an example.

I'm using Ubuntu amd64. It is reproducible on my machine and in the Playground as follows:

  1. Run. This succeeds.
  2. Format. This succeeds.
  3. Run. This fails.
@minux
Copy link
Member

minux commented Feb 28, 2015

This is working as intended.

"chan <-chan int" is parsed as "chan<- (chan int)", so if you want "chan (<-chan int)",
you have to use parenthesis. Thus gofmt is actually correct to reformat that way, and
it shows the actual meaning of that type.

http://golang.org/ref/spec#Channel_types
...
The <- operator associates with the leftmost chan possible
...

And I don't understand how your example http://play.golang.org/p/L9xzobGwob
can be broken by gofmt.

@minux minux closed this as completed Feb 28, 2015
@mikioh mikioh changed the title gofmt breaks channel syntax cmd/gofmt: breaks channel syntax Feb 28, 2015
@bgeron
Copy link
Author

bgeron commented Mar 1, 2015

Ah, I think I got confused by my own example. Apologies!

@golang golang locked and limited conversation to collaborators Jun 25, 2016
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