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: panic in methodsets.NewIndex #60628

Closed
buth opened this issue Jun 6, 2023 · 5 comments
Closed

x/tools/gopls: panic in methodsets.NewIndex #60628

buth opened this issue Jun 6, 2023 · 5 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@buth
Copy link

buth commented Jun 6, 2023

gopls version: v0.12.2 (go1.20.4)
gopls flags:
update flags: proxy
extension version: 0.38.0
go version: 1.20.4
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Tue, 06 Jun 2023 01:34:11 GMT
restart history:
Tue, 06 Jun 2023 01:29:42 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:30:36 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:30:44 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:30:47 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:31:01 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:31:34 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:32:02 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:32:14 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:32:44 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:33:04 GMT: manual (enabled: true)
Tue, 06 Jun 2023 01:34:09 GMT: manual (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

The following code immediately caused a crash.

package crash

type a[K any] *[]K

func (*a[K]) a() {}
panic: interface conversion: types.Object is nil, not *types.Func

goroutine 181 [running]:
golang.org/x/tools/internal/typeparams.OriginMethod(0x14000758660)
	  common.go:108  0x14c
golang.org/x/tools/gopls/internal/lsp/source/methodsets.(*indexBuilder).build.func2(0x140000491c0, 0x14000758660)
	  methodsets.go:248  0x1c4
golang.org/x/tools/gopls/internal/lsp/source/methodsets.methodSetInfo({0x10383ecf0, 0x1400015cc40}, 0x14000775718)
	  methodsets.go:309  0x1f0
golang.org/x/tools/gopls/internal/lsp/source/methodsets.(*indexBuilder).build(0x14000775a68, 0x14000048a00, 0x1400009c6e0)
	  methodsets.go:261  0x4f0
golang.org/x/tools/gopls/internal/lsp/source/methodsets.NewIndex(...)
	  methodsets.go:98
golang.org/x/tools/gopls/internal/lsp/cache.typeCheckImpl({0x1038427c8, 0x1400074bf50}, 0x102c206f0%3F, {{0x14000122dc8, 0x18}, {0x14000122dc8, 0x18}, {0x140002825d0, 0x5}, {0x14000226510, ...}, ...})
	  check.go:1269  0x1b4
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).checkPackage(0x1400042fec8%3F, {0x1038427c8, 0x1400074b380}, 0x14000744360)
	  check.go:634  0x190
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).handleSyntaxPackage(0x1400009c690, {0x1038427c8, 0x1400074b380}, 0x0%3F, {0x14000122dc8, 0x18})
	  check.go:518  0x3d0
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).forEachPackageInternal.func2()
	  check.go:401  0x34
golang.org/x/sync/errgroup.(*Group).Go.func1()
	  errgroup.go:75  0x5c
created by golang.org/x/sync/errgroup.(*Group).Go
	  errgroup.go:72  0xa0
[Error - 9:34:09 PM] 

OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.

NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE.
DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.

<OPTIONAL: ATTACH LOGS HERE>

@findleyr
Copy link
Contributor

findleyr commented Jun 6, 2023

Thank you for the report (especially the repro!). We will fix this gopls crash.

Moving to the Go issue tracker, since it is a gopls issue.

@findleyr findleyr changed the title gopls: automated issue report (crash) x/tools/gopls: panic in methodsets.NewIndex Jun 6, 2023
@findleyr findleyr transferred this issue from golang/vscode-go Jun 6, 2023
@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 Jun 6, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jun 6, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.12.3 Jun 6, 2023
@findleyr
Copy link
Contributor

findleyr commented Jun 6, 2023

CC @adonovan

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 6, 2023
@adonovan
Copy link
Member

adonovan commented Jun 6, 2023

Let me echo Rob's thanks for providing a minimal reproducible test case--this was a tremendous help and time-saver.

The root cause is a bug in OriginMethod for ill-typed methods where the receiver is *C[T] and the underlying type of C is itself a pointer. Obviously it's a type error to declare such a method, but OriginMethod shouldn't fail.

@adonovan adonovan self-assigned this Jun 6, 2023
@adonovan
Copy link
Member

adonovan commented Jun 6, 2023

On further digging, the problem is an inconsistency between NewMethodSet (which enumerates the methods, including the ill-typed one) and LookupFieldOrMethod (which disavows the ill-typed method). See #60634

@gopherbot
Copy link

Change https://go.dev/cl/501197 mentions this issue: internal/typeparams: work around LookupFieldOrMethod inconsistency

CarlosRosuero pushed a commit to CarlosRosuero/typeparams that referenced this issue Jun 13, 2023
This change adds to x/tools a workaround for a bug in go/types
that causes LookupFieldOrMethod and NewTypeSet to be inconsistent
wrt an ill-typed method (*T).f where T itself is a pointer.

The workaround is that, if Lookup fails, we walk the MethodSet.

Updates golang/go#60634
Fixes golang/go#60628

Change-Id: I87caa2ae077e5cdfa40b65a2f52e261384c91167
Reviewed-on: https://go-review.googlesource.com/c/tools/+/501197
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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