xtools$ cat b.go
package tools
import "fmt"
type S struct{ Bytes []byte }
var _ = struct{ A S }{
A: S{
Bytes: []byte(
fmt.Sprintf("%d", 0),
),
},
}
xtools$ go run ./gopls/internal/analysis/modernize/cmd/modernize -fix ./b.go && cat b.go package tools
import "fmt"
type S struct{ Bytes []byte }
var _ = struct{ A S }{ A: S{ Bytes: fmt.Appendf(nil, "%d", 0), , }, } ```
This code doesn't compile because the fix turned a conversion T(x)
into a simple expression x, but a conversion is permitted to have a comma after the x, as in T(x,)
even when the expression x alone is not.
Also, the fix fails to delete the spaces between "[]byte(" and "fmt", and between ")" and "," (though there are none here), which leads to strange formatting. However, deleting the spaces would also delete comments. There is no perfect answer here.