Skip to content

Commit 0098023

Browse files
committed
internal/lsp/source: fix an infinite loop in Deref function
Return a pointer type if the type refers to itself (for example, type a *a). Fixes golang/go#45510
1 parent eb71987 commit 0098023

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/lsp/source/util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,17 @@ func FormatNode(fset *token.FileSet, n ast.Node) string {
221221

222222
// Deref returns a pointer's element type, traversing as many levels as needed.
223223
// Otherwise it returns typ.
224+
//
225+
// It can return a pointer type if the type refers to itself (see golang/go#45510).
224226
func Deref(typ types.Type) types.Type {
225227
for {
226228
p, ok := typ.Underlying().(*types.Pointer)
227229
if !ok {
228230
return typ
229231
}
232+
if typ == p.Elem() {
233+
return typ
234+
}
230235
typ = p.Elem()
231236
}
232237
}

0 commit comments

Comments
 (0)