What version of Go are you using (go version)?
go version go1.11 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What did you do?
Ran gofmt on this program (https://play.golang.org/p/1rASHggr4wx):
package foo
func bar() (
// This return value is extremely subtle! Please make sure you understand
// what it does.
string,
) {
return "42"
}
What did you expect to see?
The input, unchanged.
What did you see instead?
The program reformatted with the comment in a very strange place (https://play.golang.org/p/NujRVxVN6N5):
package foo
func bar() string {// This return value is extremely subtle! Please make sure you understand
// what it does.
return "42"
}
Arguably not that common to stick a comment there, but I find the resulting code extremely surprising. Note that this nearly identical program works just fine (https://play.golang.org/p/Hpfcc5HX00l) because the presence of bazzle makes the parens required and so gofmt doesn't attempt a reformatting:
package foo
func bar() (
// This return value is extremely subtle! Please make sure you understand
// what it does.
bazzle string,
) {
return "42"
}
/cc @griesemer since you seem to get pinged on all the gofmt issues eventually
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes.
What did you do?
Ran
gofmton this program (https://play.golang.org/p/1rASHggr4wx):What did you expect to see?
The input, unchanged.
What did you see instead?
The program reformatted with the comment in a very strange place (https://play.golang.org/p/NujRVxVN6N5):
Arguably not that common to stick a comment there, but I find the resulting code extremely surprising. Note that this nearly identical program works just fine (https://play.golang.org/p/Hpfcc5HX00l) because the presence of
bazzlemakes the parens required and so gofmt doesn't attempt a reformatting:/cc @griesemer since you seem to get pinged on all the gofmt issues eventually