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

go/types: interface.Complete panics for interfaces with duplicate methods #61737

Closed
istonegithub opened this issue Aug 3, 2023 · 8 comments
Closed
Assignees
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@istonegithub
Copy link

gopls version: v0.13.1 (go1.20.4)
gopls flags:
update flags: proxy
extension version: 0.39.1
go version: 1.20.4
environment: Visual Studio Code darwin
initialization error: undefined
issue timestamp: Thu, 03 Aug 2023 05:31:10 GMT
restart history:
Wed, 02 Aug 2023 07:06:29 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: 41710: duplicate method GetByID

goroutine 9767 [running]:
go/types.computeInterfaceTypeSet.func2(0xa2ee, 0x14008235980, 0x1)
	  typeset.go:230  0x570
go/types.computeInterfaceTypeSet(0x0, 0x101123495%3F, 0x140081d3770)
	  typeset.go:257  0x21c
go/types.(*Interface).typeSet(...)
	  interface.go:29
go/types.(*Interface).Complete(...)
	  interface.go:143
golang.org/x/tools/gopls/internal/lsp/cache.typeCheckImpl({0x101576968, 0x140098a8810}, 0x10093fec0%3F, {{0x140015439c8, 0x15}, {0x140015439c8, 0x15}, {0x14001597000, 0x3}, {0x14008de5540, ...}, ...})
	  check.go:1481  0x6f8
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).checkPackage(0x1400d6c6ec8%3F, {0x101576968, 0x140090556b0}, 0x140093dde60)
	  check.go:674  0x190
golang.org/x/tools/gopls/internal/lsp/cache.(*typeCheckBatch).handleSyntaxPackage(0x14007d21da0, {0x101576968, 0x140090556b0}, 0x14000995e00%3F, {0x140015439c8, 0x15})
	  check.go:532  0x3f4
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).forEachPackageInternal.func2()
	  check.go:394  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 - 12:35:43 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
Member

findleyr commented Aug 3, 2023

Hi @istonegithub, thanks for reporting. Is this crash reproducible for you?

@findleyr
Copy link
Member

findleyr commented Aug 3, 2023

I have a reproducer:

package p

type I[P any] interface {
  m(P)
  m(P)
}

type X I[int]

Unlike var types, X will not be completed during type checking, so we encounter an incomplete interface that has duplicate methods, and therefore panic.

I'll note that we also panic when importing any package containing interfaces with duplicate methods, as the importer calls Complete(), but that panic is recovered.

CC @griesemer: I think it is incorrect for computeInterfaceTypeSet to panic here. Compare with the "cannot handle more than %d union terms..." error message in computeUnionTypeSet.

@findleyr findleyr changed the title gopls: automated issue report (crash) go/types: interface.Complete panics for interfaces with duplicate methods Aug 3, 2023
@findleyr findleyr self-assigned this Aug 3, 2023
@findleyr findleyr transferred this issue from golang/vscode-go Aug 3, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/515555 mentions this issue: go/types, types2: don't panic during interface completion

@findleyr findleyr modified the milestones: Go1.21, Go1.21.1 Aug 3, 2023
@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 3, 2023
@findleyr findleyr modified the milestones: Go1.21.1, Go1.22 Aug 3, 2023
@findleyr
Copy link
Member

findleyr commented Aug 3, 2023

@gopherbot please backport to Go 1.21. This is a deterministic panic when correctly using the go/types API.

@gopherbot
Copy link
Contributor

gopherbot commented Aug 3, 2023

Backport issue(s) opened: #61743 (for 1.21), #61744 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/515636 mentions this issue: [release-branch.go1.21] go/types, types2: don't panic during interface completion

@findleyr
Copy link
Member

findleyr commented Aug 3, 2023

@gopherbot please backport to Go 1.20. This is a deterministic panic when correctly using the go/types API.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/515638 mentions this issue: [release-branch.go1.20] go/types, types2: don't panic during interface completion

gopherbot pushed a commit that referenced this issue Aug 17, 2023
…e completion

It should be possible for the importer to construct an invalid
interface, as would have been produced by type checking.

Updates #61737
Fixes #61743

Change-Id: I72e063f4f1a6205d273a623acce2ec08c34c3cc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/515555
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Olif Oftimis <oftimisolif@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit d2ee782)
Reviewed-on: https://go-review.googlesource.com/c/go/+/515636
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
gopherbot pushed a commit that referenced this issue Aug 17, 2023
…e completion

It should be possible for the importer to construct an invalid
interface, as would have been produced by type checking.

Updates #61737
Fixes #61744

Change-Id: I72e063f4f1a6205d273a623acce2ec08c34c3cc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/515555
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Olif Oftimis <oftimisolif@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit d2ee782)
Reviewed-on: https://go-review.googlesource.com/c/go/+/515638
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
@golang golang locked and limited conversation to collaborators Aug 3, 2024
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.
Projects
None yet
Development

No branches or pull requests

4 participants