From 4fc520f0d3142a692c63b7cbb9746d3b576ce66f Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Tue, 3 Mar 2020 13:56:55 -0500 Subject: [PATCH] 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 --- go/analysis/passes/errorsas/errorsas.go | 2 +- go/analysis/passes/errorsas/testdata/src/a/a.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go/analysis/passes/errorsas/errorsas.go b/go/analysis/passes/errorsas/errorsas.go index b80271afb9..384f025570 100644 --- a/go/analysis/passes/errorsas/errorsas.go +++ b/go/analysis/passes/errorsas/errorsas.go @@ -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 diff --git a/go/analysis/passes/errorsas/testdata/src/a/a.go b/go/analysis/passes/errorsas/testdata/src/a/a.go index d13dee264f..c987a8a650 100644 --- a/go/analysis/passes/errorsas/testdata/src/a/a.go +++ b/go/analysis/passes/errorsas/testdata/src/a/a.go @@ -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()) }