mirror of https://github.com/golang/go.git
internal/lsp/source: fix completion crash in append()
We were crashing in cases like:
var _ []byte = append([]byte{}, ""...<>)
We were type asserting the type of append's second param
to *types.Slice, but in this case it is a string (*types.Basic). Fix
by checking the type assert was successful.
Note that we still don't attempt to give string completions when
appending to a byte slice. We can add that special case later once
everyone is clamoring for it.
Change-Id: I1d2fbd7f538e580d33c2dab4ef127a88e16d7ced
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219144
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:
parent
2ee7536ab1
commit
cbc0cc175f
|
|
@ -1424,7 +1424,9 @@ Nodes:
|
|||
// param w/ further expressions, we expect a single
|
||||
// variadic item.
|
||||
if beyondLastParam || isLastParam && len(node.Args) > numParams {
|
||||
inf.objType = sig.Params().At(numParams - 1).Type().(*types.Slice).Elem()
|
||||
if slice, ok := sig.Params().At(numParams - 1).Type().(*types.Slice); ok {
|
||||
inf.objType = slice.Elem()
|
||||
}
|
||||
break Nodes
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ func _() {
|
|||
|
||||
append() //@rank(")", builtinSlice, builtinChan)
|
||||
|
||||
var _ []byte = append([]byte(nil), ""...) //@rank(") //")
|
||||
|
||||
copy() //@rank(")", builtinSlice, builtinChan)
|
||||
copy(aSlice, aS) //@rank(")", builtinSlice, builtinString)
|
||||
copy(aS, aSlice) //@rank(",", builtinSlice, builtinString)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ CompletionSnippetCount = 67
|
|||
UnimportedCompletionsCount = 11
|
||||
DeepCompletionsCount = 5
|
||||
FuzzyCompletionsCount = 8
|
||||
RankedCompletionsCount = 85
|
||||
RankedCompletionsCount = 86
|
||||
CaseSensitiveCompletionsCount = 4
|
||||
DiagnosticsCount = 38
|
||||
FoldingRangesCount = 2
|
||||
|
|
|
|||
Loading…
Reference in New Issue