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/cmd/godoc: generics: type parameter incorrectly linked #50717

Open
synenka opened this issue Jan 20, 2022 · 1 comment
Open

x/tools/cmd/godoc: generics: type parameter incorrectly linked #50717

synenka opened this issue Jan 20, 2022 · 1 comment
Labels
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

@synenka
Copy link

synenka commented Jan 20, 2022

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

$ go version

go version go1.18beta1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/olenasynenka/Library/Caches/go-build"
GOENV="/Users/olenasynenka/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/olenasynenka/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/olenasynenka/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/olenasynenka/sdk/go1.18beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/olenasynenka/sdk/go1.18beta1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/olenasynenka/go/src/generics/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f8/xmg0swjx04jfwc7zln05fxlh0000gn/T/go-build495723722=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I created a generic function F with type parameter "T" and a separate struct called “T”.
Then I run cmd/godoc to view it’s documentation.

Steps to reproduce:

mkdir /tmp/test
cd /tmp/test
go mod init test
echo 'package test; func F[T any](t T) {}; type T struct{}' > test.go
go install golang.org/x/tools/cmd/godoc@latest
godoc
# In browser navigate to localhost:6060/pkg/test

What did you expect to see?

Documentation of generic func F with type param “T” used in parameter list. Type “T” doesn’t link anywhere.

What did you see instead?

Type parameter “T” is rendered with a hyper-link that links to incorrect type (struct "T").
This should not happen as struct “T” and type parameter “T” are different entities.
Screenshot

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 20, 2022
@gopherbot gopherbot added this to the Unreleased milestone Jan 20, 2022
@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 21, 2022
@gopherbot
Copy link

Change https://golang.org/cl/382714 mentions this issue: godoc: handle type parameters correctly in LinkifyText

gopherbot pushed a commit to golang/tools that referenced this issue Feb 14, 2022
LinkifyText should not generate links to global declarations for
identifiers that are type parameters.

Because the syntactic resolver does not record the declaration for type
parameters declared in the method receiver (see
https://golang.org/issue/50956) a name lookup is used as a workaround.
This is fine here because it is only applied to undeclared indentifiers
and LinkifyText is only ever called on a single declaration at a time,
not on a full AST.

Updates golang/go#50717

Change-Id: I32f2203ce80c060ee18ca8b964a2d5fd80f41957
Reviewed-on: https://go-review.googlesource.com/c/tools/+/382714
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alessandro Arzilli <alessandro.arzilli@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants