Why does errcheck fail when method is assigned to variable?
m-kru opened this issue · 3 comments
m-kru commented
I have created simple reproducer.
package main
import (
"fmt"
"strings"
)
func main() {
b := strings.Builder{}
bws := b.WriteString
bws("Lorem ipsum ...\n")
fmt.Printf(b.String())
}
[user@host errcheck]$ errcheck main.go
main.go:11:5: bws("Lorem ipsum ...\n")
[user@host errcheck]$ echo $?
1
kisielk commented
errcheck does not have a way to know the name of the function that was assigned to the variable bws
, so it cannot ignore the call.
m-kru commented
@kisielk shouldn't it then either be improved or shouldn't it ignore this check? Right now it falsely fails and breaks the CI.
kisielk commented
You can assign the result to _ to silence the error and make it explicitly ignored.