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: non-idempotent paren stripping in return type list #4624

Closed
gopherbot opened this issue Jan 7, 2013 · 2 comments
Closed

cmd/gofmt: non-idempotent paren stripping in return type list #4624

gopherbot opened this issue Jan 7, 2013 · 2 comments
Assignees
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 7, 2013

by craigm@craigm.info:

What steps will reproduce the problem?
1. http://play.golang.org/p/p2PWLtEBOO
2. click format
3. click format

package main

func a() ((int)) {
    return 1
}

package main

func a() (int) {
    return 1
}

package main

func a() int {
    return 1
}



What is the expected output?
package main

func a() int {
    return 1
}


Any number of parenthesis around the return type is reduced to 1 by the first format,
then removed by the second. This issue only applies to functions that return exactly one
value.

I'm not sure if extra parenthesis are actually legal in this case (if not, it should not
compile). If it is legal, the no return value case may be have the same/related issues:
This does not compile or format:
http://play.golang.org/p/d2JVkYPp3T

package main

func main() (()) {
}

prog.go:3: syntax error: unexpected )

And that error seems wrong too.

func main() () {
}

Works and formats as expected.
@rsc
Copy link
Contributor

@rsc rsc commented Jan 7, 2013

Comment 1:

The extra parens are allowed because in general types can be parenthesized, so
func a() ((((int))))
is okay because 
func a() (x (((int))))
is okay. I believe that what's going on here is that gofmt preserves ( ) around a type
name but does not preserve the ( ) in an unnecessarily parenthesized return value list.
So the first conversion, from
    func a() ((int)) 
to
    func a() (int)
is stripping the outer parens - they're the unnecessary parens around a lone return type
- but preserving the parens around the type itself. By doing so, it changes the meaning
of the parens to be parens around the return list, and then the next gofmt strips them
too.
So either gofmt needs to not strip the parens around a lone return type if that type is
parenthesized, or it needs to strip the parens from around the type too.

Labels changed: added priority-later, removed priority-triage.

Owner changed to @griesemer.

Status changed to Accepted.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jan 9, 2013

Comment 2:

This issue was closed by revision 0141c92.

Status changed to Fixed.

@gopherbot gopherbot added fixed labels Jan 9, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
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
3 participants
You can’t perform that action at this time.