From 41c70c91bcffeec650018664141451be12048277 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 21 Nov 2022 14:14:23 -0500 Subject: [PATCH] internal/lsp/source: avoid using go/types.Implements with Typ[Invalid] go/types predicates are undefined on types.Typ[types.Invalid]. Avoid using types.Implements with invalid types in one place. For golang/go##53595 Change-Id: I48cff1681dc7d4f59ea815e5a0d58e0160990c82 Reviewed-on: https://go-review.googlesource.com/c/tools/+/452475 Run-TryBot: Robert Findley Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot gopls-CI: kokoro Auto-Submit: Robert Findley --- gopls/internal/lsp/source/completion/postfix_snippets.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gopls/internal/lsp/source/completion/postfix_snippets.go b/gopls/internal/lsp/source/completion/postfix_snippets.go index 07d07235df..0737ec2461 100644 --- a/gopls/internal/lsp/source/completion/postfix_snippets.go +++ b/gopls/internal/lsp/source/completion/postfix_snippets.go @@ -271,7 +271,8 @@ func (a *postfixTmplArgs) VarName(t types.Type, nonNamedDefault string) string { } var name string - if types.Implements(t, errorIntf) { + // go/types predicates are undefined on types.Typ[types.Invalid]. + if !types.Identical(t, types.Typ[types.Invalid]) && types.Implements(t, errorIntf) { name = "err" } else if _, isNamed := source.Deref(t).(*types.Named); !isNamed { name = nonNamedDefault