Skip to content

Commit c531f1b

Browse files
committed
gopls/internal/golang: avoid crash in hover on field of non-struct
Avoid a crash where types.Info.TyepOf(n) is assumed to be a non-nil Struct for a StructType expr: this is not guaranteed in the presence of type errors. Unfortunately, I was not able to reproduce the crash after ~20m of trying. Nevertheless, the existing code is making invalid assumptions. Fixes golang/go#69150 Change-Id: I48abe9c134722db5c43f1c7c382b59e7632e367f Reviewed-on: https://go-review.googlesource.com/c/tools/+/627135 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent a37eeb4 commit c531f1b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gopls/internal/golang/hover.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,12 @@ func computeSizeOffsetInfo(pkg *cache.Package, path []ast.Node, obj types.Object
16271627
var tStruct *types.Struct
16281628
for _, n := range path {
16291629
if n, ok := n.(*ast.StructType); ok {
1630-
tStruct = pkg.TypesInfo().TypeOf(n).(*types.Struct)
1630+
t, ok := pkg.TypesInfo().TypeOf(n).(*types.Struct)
1631+
if ok {
1632+
// golang/go#69150: TypeOf(n) was observed not to be a Struct (likely
1633+
// nil) in some cases.
1634+
tStruct = t
1635+
}
16311636
break
16321637
}
16331638
}

0 commit comments

Comments
 (0)