Skip to content

go/types: panic "assertion failed" when autocompleting generic test code #47923

Closed
@jayconrod

Description

@jayconrod

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

$ go version
go version devel go1.18-8486ced8b0 Mon Aug 23 17:51:41 2021 +0000 linux/amd64
golang.org/x/tools/gopls v0.7.1
    golang.org/x/tools/[email protected] h1:Mh3Z8Xcoq3Zy7ksSlwDV/nzQSbjFf06A+L+F8YHq55U=

Does this issue reproduce with the latest release?

no, just master as of today

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jay/.cache/go-build"
GOENV="/home/jay/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jay/.cache/gomodcache"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jay/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/jay/Code/goroot"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/jay/Code/goroot/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-8486ced8b0 Mon Aug 23 17:51:41 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jay/Code/goroot/src/cmd/go.mod"
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-build4033947821=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Started parameterizing cmd/go/internal/par.Cache. See CL 344513.

This happened as I was adding type arguments to the cache variable in cache_test.go. The file looked like this:

// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package par

import "testing"

func TestCache(t *testing.T) {
	var cache Cache[int, ]

	n := 1
	v := cache.Do(1, func() interface{} { n++; return n })
	if v != 2 {
		t.Fatalf("cache.Do(1) did not run f")
	}
	v = cache.Do(1, func() interface{} { n++; return n })
	if v != 2 {
		t.Fatalf("cache.Do(1) ran f again!")
	}
	v = cache.Do(2, func() interface{} { n++; return n })
	if v != 3 {
		t.Fatalf("cache.Do(2) did not run f")
	}
	v = cache.Do(1, func() interface{} { n++; return n })
	if v != 2 {
		t.Fatalf("cache.Do(1) did not returned saved value from original cache.Do(1)")
	}
}

What did you expect to see?

nothing exciting

What did you see instead?

gopls crashed with the panic below:

panic: assertion failed [recovered]
	panic: assertion failed

goroutine 12647 [running]:
go/types.(*Checker).handleBailout(0xc00040cb40, 0xc011ef7690)
	/home/jay/Code/goroot/src/go/types/check.go:244 +0x8b
panic({0xc0cca0, 0xe6da40})
	/home/jay/Code/goroot/src/runtime/panic.go:814 +0x214
go/types.assert(...)
	/home/jay/Code/goroot/src/go/types/errors.go:20
go/types.(*unifier).nify(0xc00d87f440, {0xe841d8, 0xc00b6ebd40}, {0xe841d8, 0xc00d87f3b0}, 0x0)
	/home/jay/Code/goroot/src/go/types/unify.go:437 +0xe56
go/types.(*unifier).nify(0xc00d87f440, {0xe84200, 0xc009b0e970}, {0xe84200, 0xc009b0f480}, 0x0)
	/home/jay/Code/goroot/src/go/types/unify.go:325 +0x825
go/types.(*unifier).unify(...)
	/home/jay/Code/goroot/src/go/types/unify.go:60
go/types.(*Checker).infer(0xc00040cb40, {0xe71d20, 0xc01115ef50}, {0xc009b0e960, 0x2, 0x4b018}, {0x0, 0x4b029, 0x40ec8b}, 0xc0107b6408, ...)
	/home/jay/Code/goroot/src/go/types/infer.go:156 +0x688
go/types.(*Checker).selector(0xc00040cb40, 0xc00f6c9880, 0xc00f4453f8)
	/home/jay/Code/goroot/src/go/types/call.go:547 +0x1a93
go/types.(*Checker).exprInternal(0xc00040cb40, 0xc00f6c9880, {0xe867a0, 0xc00f4453f8}, {0x0, 0x0})
	/home/jay/Code/goroot/src/go/types/expr.go:1364 +0xc32
go/types.(*Checker).rawExpr(0xc006024618, 0x0, {0xe867a0, 0xc00f4453f8}, {0x0, 0x0})
	/home/jay/Code/goroot/src/go/types/expr.go:1075 +0x3a
go/types.(*Checker).exprOrType(0x1000000000000d0, 0x7fb11240f668, {0xe867a0, 0xc00f4453f8})
	/home/jay/Code/goroot/src/go/types/expr.go:1557 +0x32
go/types.(*Checker).callExpr(0xc00040cb40, 0xc00f6c9880, 0xc00f4fc200)
	/home/jay/Code/goroot/src/go/types/call.go:88 +0x2e5
go/types.(*Checker).exprInternal(0xc00040cb40, 0xc00f6c9880, {0xe86200, 0xc00f4fc200}, {0x0, 0x0})
	/home/jay/Code/goroot/src/go/types/expr.go:1408 +0x945
go/types.(*Checker).rawExpr(0xc00f6c9880, 0x0, {0xe86200, 0xc00f4fc200}, {0x0, 0x0})
	/home/jay/Code/goroot/src/go/types/expr.go:1075 +0x3a
go/types.(*Checker).multiExpr(0xd0, 0x203003, {0xe86200, 0xc00f4fc200})
	/home/jay/Code/goroot/src/go/types/expr.go:1538 +0x32
go/types.(*Checker).exprList(0x10, {0xc009b0e240, 0xc0015ec0f8, 0xc0015ec158}, 0x0)
	/home/jay/Code/goroot/src/go/types/call.go:213 +0x97
go/types.(*Checker).initVars(0xc3c940, {0xc002193e60, 0x1, 0x0}, {0xc009b0e240, 0xc00ab3ab40, 0x415545}, 0x0)
	/home/jay/Code/goroot/src/go/types/assignments.go:235 +0x7b
go/types.(*Checker).shortVarDecl(0xc00040cb40, {0xe730a0, 0xc00ef9b158}, {0xc009b0e1e0, 0x1, 0x0}, {0xc009b0e240, 0x3c2b0, 0x1})
	/home/jay/Code/goroot/src/go/types/assignments.go:367 +0x9c5
go/types.(*Checker).stmt(0xc00040cb40, 0x0, {0xe86080, 0xc00f4fc240})
	/home/jay/Code/goroot/src/go/types/stmt.go:429 +0x16a7
go/types.(*Checker).stmtList(0xe84188, 0x0, {0xc00658cc00, 0x0, 0x1})
	/home/jay/Code/goroot/src/go/types/stmt.go:130 +0xc9
go/types.(*Checker).funcBody(0xc00040cb40, 0xc00f1b9260, {0xc00040cb40, 0x7fb1124be998}, 0xc00f4fde80, 0xc00ab3ba10, {0x0, 0x0})
	/home/jay/Code/goroot/src/go/types/stmt.go:46 +0x259
go/types.(*Checker).funcDecl.func1()
	/home/jay/Code/goroot/src/go/types/decl.go:786 +0x45
go/types.(*Checker).processDelayed(0xc00040cb40, 0x0)
	/home/jay/Code/goroot/src/go/types/check.go:298 +0x35
go/types.(*Checker).checkFiles(0xc00040cb40, {0xc00f4fc880, 0xc01b6de370, 0x2})
	/home/jay/Code/goroot/src/go/types/check.go:266 +0xcb
go/types.(*Checker).Files(...)
	/home/jay/Code/goroot/src/go/types/check.go:249
golang.org/x/tools/internal/lsp/cache.doTypeCheck({0xe890d8, 0xc00f2c7ec0}, 0xc010b6c100, 0xc0085fa870, 0x2, 0xc00aebf3b0, 0xc0000320c0)
	/home/jay/.cache/gomodcache/golang.org/x/[email protected]/internal/lsp/cache/check.go:544 +0x893
golang.org/x/tools/internal/lsp/cache.typeCheck({0xe890d8, 0xc00f2c7ec0}, 0xc010b6c100, 0xc0085fa870, 0x2, 0xc00aebf3b0)
	/home/jay/.cache/gomodcache/golang.org/x/[email protected]/internal/lsp/cache/check.go:321 +0xe5
golang.org/x/tools/internal/lsp/cache.(*snapshot).buildPackageHandle.func1({0xe890d8, 0xc00f2c7ec0}, {0xe72060, 0xc010b6c100})
	/home/jay/.cache/gomodcache/golang.org/x/[email protected]/internal/lsp/cache/check.go:124 +0x23e
golang.org/x/tools/internal/memoize.(*Handle).run.func1()
	/home/jay/.cache/gomodcache/golang.org/x/[email protected]/internal/memoize/memoize.go:322 +0xa9
created by golang.org/x/tools/internal/memoize.(*Handle).run
	/home/jay/.cache/gomodcache/golang.org/x/[email protected]/internal/memoize/memoize.go:315 +0x1c5

Full output attached (too big for comment): types-assertion-failed.txt

Unfortunately, I couldn't reproduce this. Everything worked after reloading the editor window.

cc @findleyr

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions