Skip to content

Commit 4fc520f

Browse files
committed
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 <[email protected]>
1 parent 5bcca83 commit 4fc520f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

go/analysis/passes/errorsas/errorsas.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
5151
return // not enough arguments, e.g. called with return values of another function
5252
}
5353
if fn.FullName() == "errors.As" && !pointerToInterfaceOrError(pass, call.Args[1]) {
54-
pass.ReportRangef(call, "second argument to errors.As must be a pointer to an interface or a type implementing error")
54+
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")
5555
}
5656
})
5757
return nil, nil

go/analysis/passes/errorsas/testdata/src/a/a.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func _() {
3434
errors.As(nil, perr()) // *error, via a call
3535
errors.As(nil, ei) // empty interface
3636

37-
errors.As(nil, nil) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
38-
errors.As(nil, e) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
39-
errors.As(nil, m) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
40-
errors.As(nil, f) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
41-
errors.As(nil, &i) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
37+
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`
38+
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`
39+
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`
40+
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`
41+
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`
4242
errors.As(two())
4343
}

0 commit comments

Comments
 (0)