Skip to content

Commit c7e21b3

Browse files
muirdmstamblerre
authored andcommitted
internal/lsp/source: fix completion crash with untyped assignee
We were panicking when a LHS assignee's type was nil, such as: // "foo" has not been declared foo = 123 A recent refactoring changed (*completer).typeMatches() to no longer gracefully handle a nil types.Type for its first parameter. That behavior seems fine, so fix the problematic caller of typeMatches to check for nil before calling. Change-Id: Ie11e4a2d374ab1efbf6fd13fbe214e06d359fca0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/221020 Reviewed-by: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> (cherry picked from commit 8d77031) Reviewed-on: https://go-review.googlesource.com/c/tools/+/222979 Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 23e62d3 commit c7e21b3

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

internal/lsp/source/completion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,10 @@ func (ci *candidateInference) assigneesMatch(cand *candidate, sig *types.Signatu
20262026
assignee = ci.assignees[i]
20272027
}
20282028

2029+
if assignee == nil {
2030+
continue
2031+
}
2032+
20292033
allMatch, _ = ci.typeMatches(assignee, sig.Results().At(i).Type())
20302034
if !allMatch {
20312035
break

internal/lsp/testdata/lsp/primarymod/multireturn/multi_return.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func _() {
3131
var s string
3232
_, s := f //@rank(" //", multiF2Str, multiF2)
3333

34+
banana, s = f //@rank(" //", multiF2, multiF3)
35+
3436
var variadic func(int, ...int)
3537
variadic() //@rank(")", multiF1, multiF0),rank(")", multiF2, multiF0),rank(")", multiF3, multiF0)
3638
}

internal/lsp/testdata/lsp/summary.txt.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CompletionSnippetCount = 68
55
UnimportedCompletionsCount = 11
66
DeepCompletionsCount = 5
77
FuzzyCompletionsCount = 8
8-
RankedCompletionsCount = 111
8+
RankedCompletionsCount = 112
99
CaseSensitiveCompletionsCount = 4
1010
DiagnosticsCount = 39
1111
FoldingRangesCount = 2

0 commit comments

Comments
 (0)