1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:04:42 -07:00

internal/lsp/source: fix false positive "..." in completions

In cases like:

    var v interface{}
    fmt.Println(<>)

Completing to "v" would insert "v..." instead of "v". This was due to
a mixup where we were checking if the variadic type "[]interface{}"
was assignable to the candidate type "interface{}" instead of the
other way around.

Fixes golang/go#38652.

Change-Id: I27c0b50bbf4b895924c8ed2c0c9dd6785e98cbe1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229921
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Muir Manders 2020-04-24 21:19:15 -07:00 committed by Rebecca Stambler
parent 3585060312
commit 8463f397d0
3 changed files with 9 additions and 6 deletions

View File

@ -1734,8 +1734,7 @@ func (ci candidateInference) applyTypeNameModifiers(typ types.Type) types.Type {
// matchesVariadic returns true if we are completing a variadic
// parameter and candType is a compatible slice type.
func (ci candidateInference) matchesVariadic(candType types.Type) bool {
return ci.variadicType != nil && types.AssignableTo(ci.objType, candType)
return ci.variadicType != nil && types.AssignableTo(candType, ci.objType)
}
// findSwitchStmt returns an *ast.CaseClause's corresponding *ast.SwitchStmt or

View File

@ -8,9 +8,10 @@ func bar() []string { //@item(vFunc, "bar", "func() []string", "func")
func _() {
var (
i int //@item(vInt, "i", "int", "var")
s string //@item(vStr, "s", "string", "var")
ss []string //@item(vStrSlice, "ss", "[]string", "var")
i int //@item(vInt, "i", "int", "var")
s string //@item(vStr, "s", "string", "var")
ss []string //@item(vStrSlice, "ss", "[]string", "var")
v interface{} //@item(vIntf, "v", "interface{}", "var")
)
foo() //@rank(")", vInt, vStr),rank(")", vInt, vStrSlice)
@ -20,6 +21,9 @@ func _() {
// snippet will add the "..." for you
foo(123, ) //@snippet(")", vStrSlice, "ss...", "ss..."),snippet(")", vFunc, "bar()...", "bar()..."),snippet(")", vStr, "s", "s")
// don't add "..." for interface{}
foo(123, ) //@snippet(")", vIntf, "v", "v")
}
func qux(...func()) {}

View File

@ -1,7 +1,7 @@
-- summary --
CodeLensCount = 2
CompletionsCount = 237
CompletionSnippetCount = 75
CompletionSnippetCount = 76
UnimportedCompletionsCount = 6
DeepCompletionsCount = 5
FuzzyCompletionsCount = 8