Skip to content

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

Closed
@muhlemmer

Description

@muhlemmer

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/[email protected]/godoc/server.go:468 +0x19e
golang.org/x/tools/godoc.globalNames(0xc00070d8f0)
        /go/pkg/mod/golang.org/x/[email protected]/godoc/server.go:431 +0x105
golang.org/x/tools/godoc.collectExamples(0xc00014a000, 0xc000e6a089?, 0xc000e6a089?)
        /go/pkg/mod/golang.org/x/[email protected]/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/[email protected]/godoc/server.go:171 +0xb94
golang.org/x/tools/godoc.(*handlerServer).ServeHTTP(0xc0001943f8, {0xb88530, 0xc000176000}, 0xc000a76000)
        /go/pkg/mod/golang.org/x/[email protected]/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/[email protected]/godoc/pres.go:143
main.registerHandlers.func1({0xb88530?, 0xc000176000?}, 0x0?)
        /go/pkg/mod/golang.org/x/[email protected]/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions