gopls/internal/lsp/source: delete IsInterface
It differs from types.IsInterface, which is confusing. The
nil check has been moved to the caller, where applicable.
Change-Id: I07c5a4988b0d0f2d3cf01df7336268192cc74a34
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462439
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/lsp/source/completion/completion.go b/gopls/internal/lsp/source/completion/completion.go
index 92ef405..8aace97 100644
--- a/gopls/internal/lsp/source/completion/completion.go
+++ b/gopls/internal/lsp/source/completion/completion.go
@@ -2922,7 +2922,7 @@
return true
}
- if !source.IsInterface(t) && typeMatches(types.NewPointer(t)) {
+ if !types.IsInterface(t) && typeMatches(types.NewPointer(t)) {
if c.inference.typeName.compLitType {
// If we are completing a composite literal type as in
// "foo<>{}", to make a pointer we must prepend "&".
diff --git a/gopls/internal/lsp/source/completion/literal.go b/gopls/internal/lsp/source/completion/literal.go
index 2975c8f..870b97a 100644
--- a/gopls/internal/lsp/source/completion/literal.go
+++ b/gopls/internal/lsp/source/completion/literal.go
@@ -129,7 +129,7 @@
// Add a literal completion for a signature type that implements
// an interface. For example, offer "http.HandlerFunc()" when
// expected type is "http.Handler".
- if source.IsInterface(expType) {
+ if expType != nil && types.IsInterface(expType) {
c.basicLiteral(t, snip.Clone(), typeName, float64(score), addlEdits)
}
case *types.Basic:
@@ -137,7 +137,7 @@
// expected interface (e.g. named string type http.Dir
// implements http.FileSystem), or are identical to our expected
// type (i.e. yielding a type conversion such as "float64()").
- if source.IsInterface(expType) || types.Identical(expType, literalType) {
+ if expType != nil && (types.IsInterface(expType) || types.Identical(expType, literalType)) {
c.basicLiteral(t, snip.Clone(), typeName, float64(score), addlEdits)
}
}
@@ -159,7 +159,7 @@
}
// If prefix matches "func", client may want a function literal.
- if score := c.matcher.Score("func"); !cand.hasMod(reference) && score > 0 && !source.IsInterface(expType) {
+ if score := c.matcher.Score("func"); !cand.hasMod(reference) && score > 0 && (expType == nil || !types.IsInterface(expType)) {
switch t := literalType.Underlying().(type) {
case *types.Signature:
c.functionLiteral(t, float64(score))
diff --git a/gopls/internal/lsp/source/rename.go b/gopls/internal/lsp/source/rename.go
index fe2439c..1d2a03b 100644
--- a/gopls/internal/lsp/source/rename.go
+++ b/gopls/internal/lsp/source/rename.go
@@ -605,7 +605,7 @@
for _, ref := range refs {
if obj, ok := ref.obj.(*types.Func); ok {
recv := obj.Type().(*types.Signature).Recv()
- if recv != nil && IsInterface(recv.Type().Underlying()) {
+ if recv != nil && types.IsInterface(recv.Type().Underlying()) {
r.changeMethods = true
break
}
diff --git a/gopls/internal/lsp/source/rename_check.go b/gopls/internal/lsp/source/rename_check.go
index ce625de..0285fc0 100644
--- a/gopls/internal/lsp/source/rename_check.go
+++ b/gopls/internal/lsp/source/rename_check.go
@@ -552,7 +552,7 @@
// Check for conflict at point of declaration.
// Check to ensure preservation of assignability requirements.
R := recv(from).Type()
- if IsInterface(R) {
+ if types.IsInterface(R) {
// Abstract method
// declaration
@@ -569,7 +569,7 @@
for _, pkg := range r.packages {
// Start with named interface types (better errors)
for _, obj := range pkg.GetTypesInfo().Defs {
- if obj, ok := obj.(*types.TypeName); ok && IsInterface(obj.Type()) {
+ if obj, ok := obj.(*types.TypeName); ok && types.IsInterface(obj.Type()) {
f, _, _ := types.LookupFieldOrMethod(
obj.Type(), false, from.Pkg(), from.Name())
if f == nil {
@@ -641,7 +641,7 @@
// yields abstract method I.f. This can make error
// messages less than obvious.
//
- if !IsInterface(key.RHS) {
+ if !types.IsInterface(key.RHS) {
// The logic below was derived from checkSelections.
rtosel := rmethods.Lookup(from.Pkg(), r.to)
@@ -716,7 +716,7 @@
//
for key := range r.satisfy() {
// key = (lhs, rhs) where lhs is always an interface.
- if IsInterface(key.RHS) {
+ if types.IsInterface(key.RHS) {
continue
}
rsel := r.msets.MethodSet(key.RHS).Lookup(from.Pkg(), from.Name())
diff --git a/gopls/internal/lsp/source/util.go b/gopls/internal/lsp/source/util.go
index 57b1464..ec4c6bd 100644
--- a/gopls/internal/lsp/source/util.go
+++ b/gopls/internal/lsp/source/util.go
@@ -164,14 +164,6 @@
return nil, -1
}
-// IsInterface returns if a types.Type is an interface
-//
-// This function accepts nil, unlike types.IsInterface.
-// TODO(adonovan): that's confusing! Eliminate this wrapper.
-func IsInterface(T types.Type) bool {
- return T != nil && types.IsInterface(T)
-}
-
// FormatNode returns the "pretty-print" output for an ast node.
func FormatNode(fset *token.FileSet, n ast.Node) string {
var buf strings.Builder