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: Crash when an additional generic parameter is given into a generic function argument #51240

Closed
Ludonope opened this issue Feb 17, 2022 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Ludonope
Copy link

gopls version

Build info
----------
golang.org/x/tools/gopls v0.7.5
    golang.org/x/tools/gopls@v0.7.5 h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=
    github.com/BurntSushi/toml@v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
    github.com/google/go-cmp@v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd h1:lTnuArxJC+n54TyvWUPyHhrnGxYvhSi13/aM2Ndr4bs=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.1 h1:/EPr//+UMMXwMTkXvCCoaJDq8cpjMO80Ou+L4PDo2mY=
    mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
    mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ludonope/Library/Caches/go-build"
GOENV="/Users/ludonope/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ludonope/go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/ludonope/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/ludonope/sdk/go1.18beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/ludonope/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="/dev/null"
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/w4/r2qb8y9d7h36mvfyl2j4vx7h0000gn/T/go-build219769544=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

So basically I did a typo and gave two generic parameter to a type instead of one and got that crash,
I managed to reduce it all to that example

package main

type Composite[T, U any] interface {
	Method(t T)
}

func F[T Composite[U, U], U any]() {
}

type Gen[T any] interface{}

func main() {
	F[Composite[Gen[int], []int], Gen[int, int]]()
}

What did you expect to see?

I would expect to see an error on the function call in the main since the second parameter Gen[int, int] should be Gen[int].

The two following variants do not crash gopls so it seems to be the combination of Method(t T) and Gen[int, int] causing the crash.

// WITHOUT Method(t T)

package main

type Composite[T, U any] interface {
	// Method(t T)
}

func F[T Composite[U, U], U any]() {
}

type Gen[T any] interface{}

func main() {
	F[Composite[Gen[int], []int], Gen[int, int]]()
}
// WITH CORRECT Gen[int] PARAMETERS

package main

type Composite[T, U any] interface {
	Method(t T)
}

func F[T Composite[U, U], U any]() {
}

type Gen[T any] interface{}

func main() {
	F[Composite[Gen[int], []int], Gen[int]]()
}

What did you see instead?

gopls completely crashes.

Editor and settings

VSCode

Logs

panic: assertion failed [recovered]
	panic: assertion failed

goroutine 194 [running]:
go/types.(*Checker).handleBailout(0xc0005c4000, 0xc0005bf688)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/check.go:279 +0x8b
panic({0x1852340, 0x1bca940})
	/Users/ludonope/sdk/go1.18beta1/src/runtime/panic.go:838 +0x207
go/types.assert(...)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/errors.go:20
go/types.(*unifier).nify(0xc0003ad9e0, {0x1bcfea0?, 0xc000373580?}, {0x1bcfea0?, 0xc000373480?}, 0x0)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/unify.go:444 +0xd65
go/types.(*unifier).nify(0xc0003ad9e0, {0x1bcff68?, 0xc0004a6f00?}, {0x1bcff68?, 0xc0004a6f30?}, 0x0)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/unify.go:345 +0x1177
go/types.(*unifier).nify(0xc0003ad9e0, {0x1bcfef0?, 0xc0000adf00?}, {0x1bcfef0?, 0xc0000adf80?}, 0x0)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/unify.go:362 +0x937
go/types.(*unifier).unify(0xc000314b58?, {0x1bcfef0?, 0xc0000adf00?}, {0x1bcfef0?, 0xc0000adf80?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/unify.go:59 +0x30
go/types.(*Checker).missingMethod(0xc0005c4000, {0x1bcfea0?, 0xc000373400?}, 0xc00062dd40, 0x1)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/lookup.go:331 +0x6b3
go/types.(*Checker).implements(0xc0005c4000?, {0x1bcfea0?, 0xc000373400}, {0x1bcfea0?, 0xc000373500}, 0xc000293e70)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/instantiate.go:207 +0x53d
go/types.(*Checker).verify(0xc0005c4000, 0x343?, {0xc00062efa0, 0x3, 0xc00012dd40?}, {0xc00012dd40, 0x3?, 0xc00062ee40?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/instantiate.go:151 +0x1f0
go/types.(*Checker).instantiateSignature(0xc0005c4000, 0x343, 0xc0000ac180, {0xc00012dd40, 0x3, 0x3}, {0xc0002e3040, 0x3, 0x4})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/call.go:79 +0x218
go/types.(*Checker).arguments(0xc0005c4000, 0xc0002e3100, 0xc0000ac180, {0xc00012dd40, 0x3, 0x3}, {0x0?, 0x0, 0x0}, {0xc0002e3040, ...})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/call.go:392 +0x9c5
go/types.(*Checker).callExpr(0xc0005c4000, 0xc0000ad900, 0xc0002e3100)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/call.go:206 +0x669
go/types.(*Checker).exprInternal(0xc0005c4000, 0xc0000ad900, {0x1bd1f10?, 0xc0002e3100}, {0x0?, 0x0?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/expr.go:1470 +0xa12
go/types.(*Checker).rawExpr(0xc000100900?, 0xc0000ad900?, {0x1bd1f10?, 0xc0002e3100?}, {0x0?, 0x0?}, 0x0)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/expr.go:1094 +0x45
go/types.(*Checker).multiExpr(0xc0005bea30?, 0x12ac05b?, {0x1bd1f10?, 0xc0002e3100?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/expr.go:1600 +0x35
go/types.(*Checker).exprList(0xc0005d0780?, {0xc000292870?, 0x1885ba0?, 0x0?}, 0x0)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/call.go:249 +0x97
go/types.(*Checker).assignVars(0x100e8c5?, {0xc000292820?, 0x1, 0x1}, {0xc000292870?, 0x1, 0x0?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/assignments.go:378 +0x7a
go/types.(*Checker).stmt(0xc0005c4000, 0x0, {0x1bd1d90?, 0xc0002e3200?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/stmt.go:476 +0x1b48
go/types.(*Checker).stmtList(0xc0005bf4d8?, 0x0, {0xc0002928a0?, 0xc00019e240?, 0xc0005bf4f0?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/stmt.go:125 +0xc9
go/types.(*Checker).funcBody(0xc0005c4000, 0xc00062c960, {0xc0005bf628?, 0xc0004a6918?}, 0xc0000acdc0, 0xc000523b60, {0x0, 0x0})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/stmt.go:46 +0x285
go/types.(*Checker).funcDecl.func1()
	/Users/ludonope/sdk/go1.18beta1/src/go/types/decl.go:876 +0x45
go/types.(*Checker).processDelayed(0xc0005c4000, 0x0)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/check.go:348 +0x39
go/types.(*Checker).checkFiles(0xc0005c4000, {0xc0003148f8?, 0xc0001ce7d0?, 0x2?})
	/Users/ludonope/sdk/go1.18beta1/src/go/types/check.go:301 +0xcb
go/types.(*Checker).Files(...)
	/Users/ludonope/sdk/go1.18beta1/src/go/types/check.go:284
golang.org/x/tools/internal/lsp/cache.doTypeCheck({0x1bd3590, 0xc0003614c0}, 0xc000327b00, 0xc000160000, 0x2, 0xc00048ca80, 0x198a68e?)
	/Users/ludonope/go/pkg/mod/golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd/internal/lsp/cache/check.go:536 +0x8b3
golang.org/x/tools/internal/lsp/cache.typeCheck({0x1bd3590, 0xc0003614c0}, 0xc000327b00, 0xc000160000, 0x2, 0xc00048ca80?)
	/Users/ludonope/go/pkg/mod/golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd/internal/lsp/cache/check.go:313 +0xe5
golang.org/x/tools/internal/lsp/cache.(*snapshot).buildPackageHandle.func1({0x1bd3590?, 0xc0003614c0}, {0x1bccea0?, 0xc000327b00})
	/Users/ludonope/go/pkg/mod/golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd/internal/lsp/cache/check.go:124 +0x233
golang.org/x/tools/internal/memoize.(*Handle).run.func1()
	/Users/ludonope/go/pkg/mod/golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd/internal/memoize/memoize.go:327 +0xa9
created by golang.org/x/tools/internal/memoize.(*Handle).run
	/Users/ludonope/go/pkg/mod/golang.org/x/tools@v0.1.9-0.20220114220130-fd7798718afd/internal/memoize/memoize.go:320 +0x1b8
[Error - 3:30:59 PM] Connection to server got closed. Server will not be restarted.
@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 Feb 17, 2022
@gopherbot gopherbot added this to the Unreleased milestone Feb 17, 2022
@hyangah
Copy link
Contributor

hyangah commented Feb 18, 2022

@Ludonope Thanks for the report. The assertion occurred in the go/types package. Many issues related to generics were addressed since go1.18beta1 was released, and today, go1.18rc1 was released. Can you please try the go1.18rc1 (and build gopls with go1.18rc1)? (I am using go1.18rc1, and couldn't reproduce the issue)

FYI gopls v0.8.0-pre.2 will be available tomorrow. gopls v0.8.0 has many improvement for go1.18 features. If you use VSCode Go Nightly, let it pick the prerelease version. If you are using the VSCode Go stable version, try

go install golang.org/x/tools/gopls@v0.8.0-pre.2

when it becomes available.

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 18, 2022
@Ludonope
Copy link
Author

@hyangah That seems to be fixed with go1.18rc1 :)

@golang golang locked and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants