-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.
Milestone
Description
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.
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.