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
package main
import"strings"funcmain() {
varstrBuilder strings.Buildervartextstring="text"varbbyte=text[0]
strBuilder.WriteString(string(b))
}
What did I do
$ mirror --fix main.go
main.go:10:2: avoid allocations with (*strings.Builder).Write
Expected
strBuilder.WriteString(string(b)) is replaced by strBuilder.WriteByte(b)
Actual
mirror replaces strBuilder.WriteString(string(b)) with strBuilder.Write(b), which is incorrect as b is a byte and (*strings.Builder).Write takes []byte.
Minimal reproducible example:
What did I do
Expected
strBuilder.WriteString(string(b))
is replaced bystrBuilder.WriteByte(b)
Actual
mirror
replacesstrBuilder.WriteString(string(b))
withstrBuilder.Write(b)
, which is incorrect asb
is abyte
and(*strings.Builder).Write
takes[]byte
.Reference
https://pkg.go.dev/strings#Builder.Write
https://pkg.go.dev/strings#Builder.WriteByte
https://pkg.go.dev/strings#Builder.WriteString
The text was updated successfully, but these errors were encountered: