Skip to content

Commit 58e40ae

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/golang/completion: avoid crash in addFieldItems
For now, be defensive and avoid the crash reported in golang/go#72828. No attempt was made to reproduce. Longer term, as the TODO indicates, we should investigate the logic error that leads to addFieldItems being called with nil surrounding. Fixes golang/go#72828 Change-Id: I2300406b49fc3d53561b288d42f64793429e3fbd Reviewed-on: https://go-review.googlesource.com/c/tools/+/659237 Reviewed-by: Jonathan Amsterdam <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent be0d52b commit 58e40ae

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

gopls/internal/golang/completion/completion.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,10 @@ func isValidIdentifierChar(char byte) bool {
11771177

11781178
// adds struct fields, interface methods, function declaration fields to completion
11791179
func (c *completer) addFieldItems(fields *ast.FieldList) {
1180-
if fields == nil {
1180+
// TODO: in golang/go#72828, we get here with a nil surrounding.
1181+
// This indicates a logic bug elsewhere: we should only be interrogating the
1182+
// surrounding if it is set.
1183+
if fields == nil || c.surrounding == nil {
11811184
return
11821185
}
11831186

0 commit comments

Comments
 (0)