mirror of https://github.com/golang/go.git
internal/lsp/analysis/fillreturns: skip any parameterized functions
Type parameters don't have default values, so for now, we just skip them in fillreturns. I think we should still be able to handle functions whose return values are all concrete types though. Change-Id: I1fe4c0d46cd564ff71647294d6cc935762bbd9d3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/352910 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
5dbd5e40d5
commit
d42c92b465
|
|
@ -20,6 +20,7 @@ import (
|
|||
"golang.org/x/tools/go/analysis"
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/internal/analysisinternal"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
)
|
||||
|
||||
const Doc = `suggested fixes for "wrong number of return values (want %d, got %d)"
|
||||
|
|
@ -106,6 +107,14 @@ outer:
|
|||
continue
|
||||
}
|
||||
|
||||
// Skip any generic enclosing functions, since type parameters don't
|
||||
// have 0 values.
|
||||
// TODO(rstambler): We should be able to handle this if the return
|
||||
// values are all concrete types.
|
||||
if tparams := typeparams.ForFuncType(enclosingFunc); tparams != nil && tparams.NumFields() > 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Find the function declaration that encloses the ReturnStmt.
|
||||
var outer *ast.FuncDecl
|
||||
for _, p := range path {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package fillreturns
|
||||
|
||||
type Any interface{}
|
||||
|
||||
func hello[T any]() int {
|
||||
return
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package fillreturns
|
||||
|
||||
type Any interface{}
|
||||
|
||||
func hello[T any]() int {
|
||||
return
|
||||
}
|
||||
Loading…
Reference in New Issue