You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
by craigm@craigm.info:
The text was updated successfully, but these errors were encountered: