mirror of
https://github.com/golang/go
synced 2024-11-18 18:44:42 -07:00
go/analysis/passes/errorsas: clarify message
Make it clear that the second argument must be a non-nil pointer. The new message text matches the phrasing used in the errors.As doc. Updates golang/go#37625. Change-Id: I69dc2e34a5f3a5573030ba0f63f20e0821be1816 Reviewed-on: https://go-review.googlesource.com/c/tools/+/221877 Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
parent
5bcca83a78
commit
4fc520f0d3
@ -51,7 +51,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
|
||||
return // not enough arguments, e.g. called with return values of another function
|
||||
}
|
||||
if fn.FullName() == "errors.As" && !pointerToInterfaceOrError(pass, call.Args[1]) {
|
||||
pass.ReportRangef(call, "second argument to errors.As must be a pointer to an interface or a type implementing error")
|
||||
pass.ReportRangef(call, "second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type")
|
||||
}
|
||||
})
|
||||
return nil, nil
|
||||
|
10
go/analysis/passes/errorsas/testdata/src/a/a.go
vendored
10
go/analysis/passes/errorsas/testdata/src/a/a.go
vendored
@ -34,10 +34,10 @@ func _() {
|
||||
errors.As(nil, perr()) // *error, via a call
|
||||
errors.As(nil, ei) // empty interface
|
||||
|
||||
errors.As(nil, nil) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
|
||||
errors.As(nil, e) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
|
||||
errors.As(nil, m) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
|
||||
errors.As(nil, f) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
|
||||
errors.As(nil, &i) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
|
||||
errors.As(nil, nil) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
|
||||
errors.As(nil, e) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
|
||||
errors.As(nil, m) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
|
||||
errors.As(nil, f) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
|
||||
errors.As(nil, &i) // want `second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type`
|
||||
errors.As(two())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user