diff --git a/go/analysis/passes/errorsas/errorsas.go b/go/analysis/passes/errorsas/errorsas.go index 337a61d8..c411466c 100644 --- a/go/analysis/passes/errorsas/errorsas.go +++ b/go/analysis/passes/errorsas/errorsas.go @@ -47,6 +47,9 @@ func run(pass *analysis.Pass) (interface{}, error) { if fn == nil { 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]) { pass.Reportf(call.Pos(), "second argument to errors.As must be a pointer to an interface or a type implementing error") } diff --git a/go/analysis/passes/errorsas/testdata/src/a/a.go b/go/analysis/passes/errorsas/testdata/src/a/a.go index bebf2679..d13dee26 100644 --- a/go/analysis/passes/errorsas/testdata/src/a/a.go +++ b/go/analysis/passes/errorsas/testdata/src/a/a.go @@ -18,6 +18,8 @@ type iface interface { m() } +func two() (error, interface{}) { return nil, nil } + func _() { var ( 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, 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(two()) }