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>
diff --git a/internal/lsp/analysis/fillreturns/fillreturns.go b/internal/lsp/analysis/fillreturns/fillreturns.go
index 94accef..d34baf5 100644
--- a/internal/lsp/analysis/fillreturns/fillreturns.go
+++ b/internal/lsp/analysis/fillreturns/fillreturns.go
@@ -20,6 +20,7 @@
 	"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 @@
 			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 {
diff --git a/internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go b/internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go
new file mode 100644
index 0000000..8c371ea
--- /dev/null
+++ b/internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go
@@ -0,0 +1,10 @@
+//go:build go1.18
+// +build go1.18
+
+package fillreturns
+
+type Any interface{}
+
+func hello[T any]() int {
+	return
+}
diff --git a/internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go.golden b/internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go.golden
new file mode 100644
index 0000000..8c371ea
--- /dev/null
+++ b/internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go.golden
@@ -0,0 +1,10 @@
+//go:build go1.18
+// +build go1.18
+
+package fillreturns
+
+type Any interface{}
+
+func hello[T any]() int {
+	return
+}