diff --git a/go/analysis/passes/httpmux/httpmux.go b/go/analysis/passes/httpmux/httpmux.go index d13e8aab37b..78748c5c12e 100644 --- a/go/analysis/passes/httpmux/httpmux.go +++ b/go/analysis/passes/httpmux/httpmux.go @@ -84,26 +84,29 @@ func isServeMuxRegisterCall(pass *analysis.Pass, call *ast.CallExpr) bool { if !isMethodNamed(fn, "net/http", "Handle", "HandleFunc") { return false } - isPtr, named := typesinternal.ReceiverNamed(fn.Type().(*types.Signature).Recv()) + recv := fn.Type().(*types.Signature).Recv() // isMethodNamed() -> non-nil + isPtr, named := typesinternal.ReceiverNamed(recv) return isPtr && analysisutil.IsNamedType(named, "net/http", "ServeMux") } +// isMethodNamed reports when a function f is a method, +// in a package with the path pkgPath and the name of f is in names. func isMethodNamed(f *types.Func, pkgPath string, names ...string) bool { if f == nil { return false } if f.Pkg() == nil || f.Pkg().Path() != pkgPath { - return false + return false // not at pkgPath } if f.Type().(*types.Signature).Recv() == nil { - return false + return false // not a method } for _, n := range names { if f.Name() == n { return true } } - return false + return false // not in names } // stringConstantExpr returns expression's string constant value. diff --git a/go/analysis/passes/httpresponse/httpresponse.go b/go/analysis/passes/httpresponse/httpresponse.go index 047ae07cca1..e1ca9b2f514 100644 --- a/go/analysis/passes/httpresponse/httpresponse.go +++ b/go/analysis/passes/httpresponse/httpresponse.go @@ -119,7 +119,7 @@ func isHTTPFuncOrMethodOnClient(info *types.Info, expr *ast.CallExpr) bool { return false // the function called does not return two values. } isPtr, named := typesinternal.ReceiverNamed(res.At(0)) - if !isPtr || !analysisutil.IsNamedType(named, "net/http", "Response") { + if !isPtr || named == nil || !analysisutil.IsNamedType(named, "net/http", "Response") { return false // the first return type is not *http.Response. } diff --git a/go/analysis/passes/httpresponse/testdata/src/a/a.go b/go/analysis/passes/httpresponse/testdata/src/a/a.go index de41212703e..d0988fc7b0b 100644 --- a/go/analysis/passes/httpresponse/testdata/src/a/a.go +++ b/go/analysis/passes/httpresponse/testdata/src/a/a.go @@ -110,3 +110,12 @@ func badUnwrapResp() { log.Fatal(err) } } + +type i66259 struct{} + +func (_ *i66259) Foo() (*int, int) { return nil, 1 } + +func issue66259() { + var f *i66259 + f.Foo() +}