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/go2go: crash when using an imported constraint with an embedded constraint #39868

Closed
argusdusty opened this issue Jun 26, 2020 · 1 comment
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@argusdusty
Copy link

argusdusty commented Jun 26, 2020

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

C:\Users\argusdusty\Code\src\foo>go version
go version devel +abe4d3dce1 Tue Dec 8 17:59:47 2020 +0000 windows/amd64

Does this issue reproduce with the latest release?

Reproduces on abe4d3d

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

go env Output
C:\Users\argusdusty\Code\src\foo>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\argusdusty\AppData\Local\go-build
set GOENV=C:\Users\argusdusty\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\argusdusty\Code\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\argusdusty\Code
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Gosrc
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Gosrc\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=
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 -fmessage-length=0 -fdebug-prefix-map=C:\Users\ARGUSD~1\AppData\Local\Temp\go-build246512954=/tmp/go-build -gno-record-gcc-switches

What did you do?

foo/lib/lib.go2:

package lib

type Bar[T any] interface {
	comparable
	F1() T
}

func F2[T Bar[T]]() { println("Hello, World!") }

foo/foo.go2:

package main

import "foo/lib"

type Foo int

func (F Foo) F1() Foo { return F }

func main() { lib.F2[Foo]() }

C:\Users\argusdusty\Code\src\foo>go tool go2go build

What did you expect to see?

Successful compilation.

What did you see instead?

panic: runtime error: index out of range [0] with length 0

Stack Trace:
goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc00009e3c0, 0xc0000c99f8)
        C:/Gosrc/src/go/types/check.go:252 +0xa5
panic(0xcea5a0, 0xc0000a0ca0)
        C:/Gosrc/src/runtime/panic.go:969 +0x176
go/types.(*Checker).stmt.func1(0xc00009e3c0, 0xc000134050)
        C:/Gosrc/src/go/types/stmt.go:307 +0x8c
panic(0xcea5a0, 0xc0000a0ca0)
        C:/Gosrc/src/runtime/panic.go:975 +0x3e9
go/types.(*Checker).completeInterface(0xc00009e3c0, 0x0, 0xc0000e6580)
        C:/Gosrc/src/go/types/typexpr.go:917 +0x7b9
go/types.(*subster).typ(0xc0000c7618, 0xd54780, 0xc0000e6480, 0x0, 0x0)
        C:/Gosrc/src/go/types/subst.go:322 +0x19d9
go/types.(*Checker).subst(0xc00009e3c0, 0x70, 0xd54780, 0xc0000e6480, 0xc000099220, 0x1, 0xc000099220)
        C:/Gosrc/src/go/types/subst.go:240 +0x12b
go/types.(*Checker).instantiate(0xc00009e3c0, 0x69, 0xd54880, 0xc0000d2480, 0xc000088950, 0x1, 0x1, 0xc0000a2990, 0x1, 0x1, ...)
        C:/Gosrc/src/go/types/subst.go:139 +0x2aa
go/types.(*Checker).call(0xc00009e3c0, 0xc0000f0ac0, 0xc0001340f0, 0xd57100, 0xc0000b6f00, 0xa63df3)
        C:/Gosrc/src/go/types/call.go:176 +0x538
go/types.(*Checker).exprInternal(0xc00009e3c0, 0xc0000f0ac0, 0xd57100, 0xc0000b6f00, 0x0, 0x0, 0xfd44552e)
        C:/Gosrc/src/go/types/expr.go:1359 +0x2bbe
go/types.(*Checker).rawExpr(0xc00009e3c0, 0xc0000f0ac0, 0xd57100, 0xc0000b6f00, 0x0, 0x0, 0x0)
        C:/Gosrc/src/go/types/expr.go:1043 +0xc7
go/types.(*Checker).exprOrType(0xc00009e3c0, 0xc0000f0ac0, 0xd57100, 0xc0000b6f00)
        C:/Gosrc/src/go/types/expr.go:1785 +0x5c
go/types.(*Checker).call(0xc00009e3c0, 0xc0000f0ac0, 0xc0000d5450, 0xd56c00, 0xc0000d5450, 0xa7693b)
        C:/Gosrc/src/go/types/call.go:21 +0xd7
go/types.(*Checker).exprInternal(0xc00009e3c0, 0xc0000f0ac0, 0xd56c00, 0xc0000d5450, 0x0, 0x0, 0x38)
        C:/Gosrc/src/go/types/expr.go:1637 +0x1d3a
go/types.(*Checker).rawExpr(0xc00009e3c0, 0xc0000f0ac0, 0xd56c00, 0xc0000d5450, 0x0, 0x0, 0x0)
        C:/Gosrc/src/go/types/expr.go:1043 +0xc7
go/types.(*Checker).stmt(0xc00009e3c0, 0x0, 0xd56e40, 0xc0000885d0)
        C:/Gosrc/src/go/types/stmt.go:333 +0x3dbb
go/types.(*Checker).stmtList(0xc00009e3c0, 0x0, 0xc0000885e0, 0x1, 0x1)
        C:/Gosrc/src/go/types/stmt.go:125 +0xd6
go/types.(*Checker).funcBody(0xc00009e3c0, 0xc0000d2720, 0xc0000a25a0, 0x4, 0xc0000d27e0, 0xc0000b6f30, 0x0, 0x0)
        C:/Gosrc/src/go/types/stmt.go:42 +0x268
go/types.(*Checker).funcDecl.func1()
        C:/Gosrc/src/go/types/decl.go:813 +0x6e
go/types.(*Checker).processDelayed(0xc00009e3c0, 0x0)
        C:/Gosrc/src/go/types/check.go:327 +0x45
go/types.(*Checker).checkFiles(0xc00009e3c0, 0xc0000cc090, 0x1, 0x1, 0x0, 0x0)
        C:/Gosrc/src/go/types/check.go:295 +0x20d
go/types.(*Checker).Files(...)
        C:/Gosrc/src/go/types/check.go:257
go/types.(*Config).Check(0xc0000f0400, 0xc0000a2550, 0x4, 0xc0000f0240, 0xc0000cc090, 0x1, 0x1, 0xc0000d5360, 0x1, 0x1, ...)
        C:/Gosrc/src/go/types/api.go:392 +0x188
go/go2go.rewriteFilesInPath(0xc0000d2240, 0x0, 0x0, 0xd06733, 0x1, 0xc0000b6c60, 0x1, 0x3, 0x0, 0x0, ...)
        C:/Gosrc/src/go/go2go/go2go.go:94 +0x4f6
go/go2go.rewriteToPkgs(0xc0000d2240, 0x0, 0x0, 0xd06733, 0x1, 0xc0000985c0, 0xc0000b6ab0, 0xc0000b6a80, 0xc0000b6a50, 0xc0000b6a20)
        C:/Gosrc/src/go/go2go/go2go.go:46 +0x16e
go/go2go.Rewrite(...)
        C:/Gosrc/src/go/go2go/go2go.go:30
main.translate(0xc0000d2240, 0xd06733, 0x1)
        C:/Gosrc/src/cmd/go2go/translate.go:15 +0x4e
main.main()
        C:/Gosrc/src/cmd/go2go/main.go:78 +0xa0c

Based on my testing, this crash occurs when all of the following conditions are met:

  1. The generic type must be from another package. The equivalent single-package code compiles/runs fine: https://go2goplay.golang.org/p/Y6GbuLmMw0-
  2. The generic type must contain at least one embedded constraint. Any embedded constraint will do, even an empty one.
  3. The generic type must contain at least one function that references the type parameter. Changing F1() T to F1() int and similarly adjusting Foo will run fine, but F1(T), F1([]T), F1() []T, etc. all crash.
  4. Though it isn't valid code, the Foo type doesn't need to filled in, or exist at all: func main() { lib.F2[int]() } triggers the same compiler crash.
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 26, 2020
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 26, 2020
@argusdusty
Copy link
Author

This issue no longer occurs in the Go 1.18 Beta 1 release, so closing it.

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants