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

cmd/compile/internal/types2: panic when type function selector is not instantiated #48048

Closed
qmuntal opened this issue Aug 29, 2021 · 2 comments
Closed
Assignees
Milestone

Comments

@qmuntal
Copy link
Contributor

@qmuntal qmuntal commented Aug 29, 2021

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

go version devel go1.18-f29abccd8a Sun Aug 29 14:10:21 2021 +0000 windows/amd64

Does this issue reproduce with the latest release?

Only tip

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

go env Output
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Dante\AppData\Local\go-build
set GOENV=C:\Users\Dante\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Dante\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Dante\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\Dante\Documents\Code\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\Dante\Documents\Code\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.18-f29abccd8a Sun Aug 29 14:10:21 2021 +0000
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Dante\Documents\Code\go-test\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Dante\AppData\Local\Temp\go-build3680751562=/tmp/go-build -gno-record-gcc-switches

What did you do?

type T[P any] struct{}

func (T[_]) A() {}

var _ = (*T).A

What did you expect to see?

cannot use generic type T[P interface{}] without instantiation

What did you see instead?

panic: assertion failed [recovered]
        panic: assertion failed

goroutine 1 [running]:
cmd/compile/internal/types2.(*Checker).handleBailout(0xc000104780, 0xc00011f658)
        /go/src/cmd/compile/internal/types2/check.go:240 +0x8b
panic({0x1693f00, 0x187e0e0})
        /go/src/runtime/panic.go:814 +0x214
cmd/compile/internal/types2.assert(...)
        /go/src/cmd/compile/internal/types2/errors.go:23
cmd/compile/internal/types2.(*unifier).nify(0xc00016a480, {0x188c658, 0xc00016a3f0}, {0x188c658, 0xc00016a2d0}, 0x0)
        /go/src/cmd/compile/internal/types2/unify.go:437 +0x1074
cmd/compile/internal/types2.(*unifier).unify(...)
        /go/src/cmd/compile/internal/types2/unify.go:59
cmd/compile/internal/types2.(*Checker).infer(0xc000104780, {0xc0003c7320, 0x1, 0x0}, {0xc000006500, 0x1, 0x8}, {0x0, 0x0, 0x0}, ...)
        /go/src/cmd/compile/internal/types2/infer.go:156 +0x708
cmd/compile/internal/types2.(*Checker).selector(0xc000104780, 0xc00003ba40, 0xc0003c73e0)
        /go/src/cmd/compile/internal/types2/call.go:562 +0x1b85
cmd/compile/internal/types2.(*Checker).exprInternal(0xc000104780, 0xc00003ba40, {0x188d7f0, 0xc0003c73e0}, {0x0, 0x0})
        /go/src/cmd/compile/internal/types2/expr.go:1394 +0x765
cmd/compile/internal/types2.(*Checker).rawExpr(0xc000104780, 0xc00003ba40, {0x188d7f0, 0xc0003c73e0}, {0x0, 0x0})
        /go/src/cmd/compile/internal/types2/expr.go:1099 +0x1aa
cmd/compile/internal/types2.(*Checker).expr(0x0, 0xc00003b780, {0x188d7f0, 0xc0003c73e0})
        /go/src/cmd/compile/internal/types2/expr.go:1599 +0x32
cmd/compile/internal/types2.(*Checker).varDecl(0x16ad740, 0xc000071ce0, {0xc0000064a8, 0x0, 0xc000072500}, {0x0, 0x0}, {0x188d7f0, 0xc0003c73e0})
        /go/src/cmd/compile/internal/types2/decl.go:485 +0x1f6
cmd/compile/internal/types2.(*Checker).objDecl(0xc000104780, {0x189e738, 0xc000071ce0}, 0x10)
        /go/src/cmd/compile/internal/types2/decl.go:194 +0x965
cmd/compile/internal/types2.(*Checker).packageObjects(0xc000104780)
        /go/src/cmd/compile/internal/types2/resolver.go:679 +0x385
cmd/compile/internal/types2.(*Checker).checkFiles(0xc000104780, {0xc000064c10, 0x0, 0x0})
        /go/src/cmd/compile/internal/types2/check.go:269 +0x25f
cmd/compile/internal/types2.(*Checker).Files(...)
        /go/src/cmd/compile/internal/types2/check.go:245
cmd/compile/internal/noder.checkFiles({0xc000064b90, 0x2, 0x283d4f3b0e8})
        /go/src/cmd/compile/internal/noder/irgen.go:65 +0x43e
cmd/compile/internal/noder.check2({0xc000064b90, 0x2, 0x2})
        /go/src/cmd/compile/internal/noder/irgen.go:78 +0x46
cmd/compile/internal/noder.LoadPackage({0xc0001280e0, 0x2, 0x0})
        /go/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x17565b8)
        /go/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        /go/src/cmd/compile/main.go:55 +0xdd

@griesemer

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 29, 2021

Change https://golang.org/cl/345970 mentions this issue: go/types, types2: types in type func selector must be instantiated

Loading

@griesemer griesemer self-assigned this Aug 29, 2021
@griesemer griesemer added this to the Go1.18 milestone Aug 29, 2021
@gopherbot gopherbot closed this in 86fa510 Aug 30, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 1, 2021

Change https://golang.org/cl/346471 mentions this issue: cmd/compile/internal/types2: systematic detection of missing instantiation

Loading

gopherbot pushed a commit that referenced this issue Sep 1, 2021
…ation

When type-checking expressions, detection of uninstantiated generic
functions and types was somewhat ad-hoc.

Add an extra parameter "allowGenerics" to rawExpr. If not set, the
result operand cannot be generic.

The only place where rawExpr is called with allowGenerics != false
is from exprOrType, which passes an allowGenerics parameter through.

The only place where exprOrType is called with allowGenerics == true
is when handling index expressions and calls. Make sure that we only
accept generic operands where expected, and check the other branches.

As a result, a recently added varType call (CL 345970) can be removed
again.

This also fixes a bug where an error for a conversion to generic
type was reported after the conversion (i.e., with the converted
value, rather than the generic type). Added a test case for that.

For #48048.

Change-Id: I8576326f5fcfb58d78b3ce8572068aa32e66c568
Reviewed-on: https://go-review.googlesource.com/c/go/+/346471
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants