Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: recovered panic in RenderPackageDoc #66449

Closed
adonovan opened this issue Mar 21, 2024 · 2 comments
Closed

x/tools/gopls: recovered panic in RenderPackageDoc #66449

adonovan opened this issue Mar 21, 2024 · 2 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

Steps:

  1. Clone repo and visit this file: https://codeberg.org/pfad.fr/vanitydoc/src/branch/main/example/nested/chan.go
  2. Source Actions > View Package Documentation...

Observe panic (recovered by net/http) below.

The offending line is:

buf.WriteString(escape(string(file.Src[start:end])))
panic serving 127.0.0.1:58457: runtime error: slice bounds out of range [:-1]
goroutine 4715 [running]:
net/http.(*conn).serve.func1()
	/Users/adonovan/w/goroot/src/net/http/server.go:1898 +0xb0
panic({0x105945a00?, 0x14007088978?})
	/Users/adonovan/w/goroot/src/runtime/panic.go:759 +0x124
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func4.2(0x0)
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:187 +0xfc
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func4.3({0x1059aa120?, 0x106001dc0})
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:193 +0x128
go/ast.inspector.Visit(0x1400191b350, {0x1059aa120?, 0x106001dc0?})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:386 +0x38
go/ast.Walk({0x1059a6dc0?, 0x1400191b350?}, {0x1059aa120, 0x106001dc0})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:51 +0x44
go/ast.walkIdentList(...)
	/Users/adonovan/w/goroot/src/go/ast/walk.go:20
go/ast.Walk({0x1059a6dc0?, 0x1400191b350?}, {0x1059aa988, 0x1400210cb90})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:314 +0x661
go/ast.Walk({0x1059a6dc0?, 0x1400191b350?}, {0x1059aa618, 0x140018d5b40})
	/Users/adonovan/w/goroot/src/go/ast/walk.go:344 +0x20e8
go/ast.Inspect(...)
	/Users/adonovan/w/goroot/src/go/ast/walk.go:397
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func4({0x1059aa618, 0x140018d5b40})
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:190 +0x1e5
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc.func6({0x140023b2780, 0x16, 0x105530eb5?})
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:300 +0x5c
golang.org/x/tools/gopls/internal/golang.RenderPackageDoc(0x14006893c80, 0x14002949860, 0x140080432f0)
	/Users/adonovan/w/xtools/gopls/internal/golang/pkgdoc.go:316 +0x958

@oliverpool

@adonovan adonovan self-assigned this Mar 21, 2024
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 21, 2024
@gopherbot gopherbot added this to the Unreleased milestone Mar 21, 2024
@adonovan
Copy link
Member Author

adonovan commented Mar 21, 2024

This appears to be a consequence of doc.New mutating the AST, even though it is not permitted to do so in PreserveAST mode. The NamePos of the ok Ident becomes zero. Still investigating...

@gopherbot
Copy link

Change https://go.dev/cl/573575 mentions this issue: gopls/internal/golang: work around bug in go/doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants