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/godoc: panic with generic type with methods #50413

Closed
muhlemmer opened this issue Jan 3, 2022 · 2 comments
Closed

x/tools/godoc: panic with generic type with methods #50413

muhlemmer opened this issue Jan 3, 2022 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@muhlemmer
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.18beta1 linux/amd64

$ gotip version
go version devel go1.18-c8861432b8 Sun Jan 2 14:27:43 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

Beta1 release of Go 1.18 and master through gotip with type parameter support.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vscode/.cache/go-build"
GOENV="/home/vscode/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspaces/godoc_generics_issue/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1808945237=/tmp/go-build -gno-record-gcc-switches"
gotip env Output
$ gotip env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vscode/.cache/go-build"
GOENV="/home/vscode/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/vscode/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/vscode/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-c8861432b8 Sun Jan 2 14:27:43 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspaces/godoc_generics_issue/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build338508180=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Add a generic (struct) type with methods:

type MyType[T any] struct {
	i T
}

func (m *MyType[T]) Set(i T) {
	m.i = i
}

func (m *MyType[T]) Get() T {
	return m.i
}

Install and run godoc using go or gotip, the issue appears on both builds:

go install golang.org/x/tools/cmd/godoc@master
cd <into module directory>
godoc -http=:6060

From other terminal:

curl localhost:6060/pkg/github.com/muhlemmer/godoc_generics_issue/

What did you expect to see?

HTML output of the documentation for the package

What did you see instead?

curl terminal:

curl: (52) Empty reply from server

godoc terminal:

using module mode; GOMOD=/workspaces/godoc_generics_issue/go.mod
go: no module dependencies to download
2022/01/03 14:06:01 http: panic serving 127.0.0.1:55864: interface conversion: ast.Expr is *ast.IndexExpr, not *ast.Ident
goroutine 1151 [running]:
net/http.(*conn).serve.func1()
        /home/vscode/sdk/gotip/src/net/http/server.go:1825 +0xbf
panic({0x9869e0, 0xc00070dad0})
        /home/vscode/sdk/gotip/src/runtime/panic.go:844 +0x258
golang.org/x/tools/godoc.addNames(0x7ff27f9955b8?, {0xb87b10?, 0xc00070d5f0?})
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/godoc/server.go:468 +0x19e
golang.org/x/tools/godoc.globalNames(0xc00070d8f0)
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/godoc/server.go:431 +0x105
golang.org/x/tools/godoc.collectExamples(0xc00014a000, 0xc000e6a089?, 0xc000e6a089?)
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/godoc/server.go:445 +0x132
golang.org/x/tools/godoc.(*handlerServer).GetPageInfo(0xc0001943f8, {0xc001220120, 0x2e}, {0xc000e6a089, 0x29}, 0x0, {0x0, 0x0}, {0x0, 0x0})
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/godoc/server.go:171 +0xb94
golang.org/x/tools/godoc.(*handlerServer).ServeHTTP(0xc0001943f8, {0xb88530, 0xc000176000}, 0xc000a76000)
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/godoc/server.go:276 +0x23c
net/http.(*ServeMux).ServeHTTP(0xc000516051?, {0xb88530, 0xc000176000}, 0xc000a76000)
        /home/vscode/sdk/gotip/src/net/http/server.go:2462 +0x149
golang.org/x/tools/godoc.(*Presentation).ServeHTTP(...)
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/godoc/pres.go:143
main.registerHandlers.func1({0xb88530?, 0xc000176000?}, 0x0?)
        /go/pkg/mod/golang.org/x/tools@v0.1.9-0.20211228192929-ee1ca4ffc4da/cmd/godoc/handlers.go:36 +0x6e
net/http.HandlerFunc.ServeHTTP(0x0?, {0xb88530?, 0xc000176000?}, 0x0?)
        /home/vscode/sdk/gotip/src/net/http/server.go:2084 +0x2f
net/http.(*ServeMux).ServeHTTP(0x7ff258327d98?, {0xb88530, 0xc000176000}, 0xc000a76000)
        /home/vscode/sdk/gotip/src/net/http/server.go:2462 +0x149
net/http.(*ServeMux).ServeHTTP(0x0?, {0xb88530, 0xc000176000}, 0xc000a76000)
        /home/vscode/sdk/gotip/src/net/http/server.go:2462 +0x149
net/http.serverHandler.ServeHTTP({0xc00070cc00?}, {0xb88530, 0xc000176000}, 0xc000a76000)
        /home/vscode/sdk/gotip/src/net/http/server.go:2916 +0x43b
net/http.(*conn).serve(0xc0000ba280, {0xb88b20, 0xc00070ea50})
        /home/vscode/sdk/gotip/src/net/http/server.go:1966 +0x5d7
created by net/http.(*Server).Serve
        /home/vscode/sdk/gotip/src/net/http/server.go:3071 +0x4db

Additional info:

Possibly related to #50412, although the panic seems to be limited to the godoc package itself.

@findleyr
Copy link
Contributor

findleyr commented Jan 3, 2022

Thank you for the report. godoc is deprecated (see #49212), and has not been updated for generics. We (the go team) probably won't get to this any time soon, though we'd accept community contributions. We'll fix the related issue in pkgsite (thanks for reporting that as well).

@gopherbot
Copy link

Change https://golang.org/cl/373857 mentions this issue: godoc: fix addNames for generics

@dmitshur dmitshur changed the title godoc: panic with generic type with methods x/tools/godoc: panic with generic type with methods Jan 4, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 4, 2022
@gopherbot gopherbot added this to the Unreleased milestone Jan 4, 2022
@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 13, 2022
@golang golang locked and limited conversation to collaborators Jan 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants