errorsas: handle single-actual case
Handle the case where there is syntactically only one actual argument passed to errors.As. Following the unmarshal check, we ignore this case. Change-Id: Ia7d77d5b3c9eb5416b37a141104c9ad7ed290b5f Reviewed-on: https://go-review.googlesource.com/c/tools/+/178159 Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
b1dcc6b189
commit
0abef6e9ec
|
@ -47,6 +47,9 @@ func run(pass *analysis.Pass) (interface{}, error) {
|
||||||
if fn == nil {
|
if fn == nil {
|
||||||
return // not a static call
|
return // not a static call
|
||||||
}
|
}
|
||||||
|
if len(call.Args) < 2 {
|
||||||
|
return // not enough arguments, e.g. called with return values of another function
|
||||||
|
}
|
||||||
if fn.FullName() == "errors.As" && !pointerToInterfaceOrError(pass, call.Args[1]) {
|
if fn.FullName() == "errors.As" && !pointerToInterfaceOrError(pass, call.Args[1]) {
|
||||||
pass.Reportf(call.Pos(), "second argument to errors.As must be a pointer to an interface or a type implementing error")
|
pass.Reportf(call.Pos(), "second argument to errors.As must be a pointer to an interface or a type implementing error")
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ type iface interface {
|
||||||
m()
|
m()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func two() (error, interface{}) { return nil, nil }
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
var (
|
var (
|
||||||
e error
|
e error
|
||||||
|
@ -37,4 +39,5 @@ func _() {
|
||||||
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, 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, 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, &i) // want `second argument to errors.As must be a pointer to an interface or a type implementing error`
|
||||||
|
errors.As(two())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue