Skip to content

Commit 8ba9169

Browse files
committed
gopls/internal/golang: Highlight: work around go/types bug
go/types sometimes fails to annotate type information onto nested composite literals when there is a type error (#69092). This CL adds a workaround to one particularly vulnerable place in gopls that crashes when this happens. (There are potentially many others.) + test Fixes golang/go#68918 Change-Id: I73e8e1dd8eb8965bde44d8ee3672a50ac362af52 Reviewed-on: https://go-review.googlesource.com/c/tools/+/612042 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent bfc94c9 commit 8ba9169

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

gopls/internal/golang/highlight.go

+5
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ func highlightIdentifier(id *ast.Ident, file *ast.File, info *types.Info, result
558558
highlightWriteInExpr(n.Chan)
559559
case *ast.CompositeLit:
560560
t := info.TypeOf(n)
561+
// Every expression should have a type;
562+
// work around https://github.com/golang/go/issues/69092.
563+
if t == nil {
564+
t = types.Typ[types.Invalid]
565+
}
561566
if ptr, ok := t.Underlying().(*types.Pointer); ok {
562567
t = ptr.Elem()
563568
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Regression test for https://github.com/golang/go/issues/68918:
2+
crash due to missing type information in CompositeLit.
3+
4+
-- a.go --
5+
package a
6+
7+
var _ = T{{ x }} //@hiloc(x, "x", text), diag("T", re"undefined"), diag("{ ", re"missing type")
8+
9+
//@highlight(x, x)

0 commit comments

Comments
 (0)