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

Open
argusdusty opened this issue Jun 26, 2020 · 0 comments
Open
Assignees
Milestone

Comments

@argusdusty
Copy link

@argusdusty 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 +1b08acee45 Thu Jun 25 23:22:18 2020 +0000 windows/amd64

Does this issue reproduce with the latest release?

Reproduces on 1b08ace

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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\ARGUSD~1\AppData\Local\Temp\go-build241823034=/tmp/go-build -gno-record-gcc-switches

What did you do?

foo/lib/lib.go2:

package lib

type Bar(type T) interface {
	comparable
	F1() T
}

func F2(type T Bar)() { 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:
panic: runtime error: index out of range [0] with length 0 [recovered]
        panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc0000e06c0, 0xc0000c99f8)
C:/Gosrc/src/go/types/check.go:251 +0x9f
panic(0xeaba20, 0xc0000a10c0)
C:/Gosrc/src/runtime/panic.go:969 +0x176
go/types.(*Checker).completeInterface(0xc0000e06c0, 0x0, 0xc0000e8600)
C:/Gosrc/src/go/types/typexpr.go:898 +0x75a
go/types.(*subster).typ(0xc0000c60c0, 0xf1d860, 0xc0000e8580, 0x0, 0x0)
C:/Gosrc/src/go/types/subst.go:310 +0x19d9
go/types.(*Checker).subst(0xc0000e06c0, 0x84, 0xf1d860, 0xc0000e8580, 0xc000099660, 0x1, 0xc000099660)
C:/Gosrc/src/go/types/subst.go:229 +0x12b
go/types.(*Checker).instantiate(0xc0000e06c0, 0x72, 0xf1dae0, 0xc0000d44e0, 0xc000088b00, 0x1, 0x1, 0xc0000a2a80, 0x1, 0x1, ...)
C:/Gosrc/src/go/types/subst.go:138 +0x2b9
go/types.(*Checker).call(0xc0000e06c0, 0xc0000d36c0, 0xc0000d2400, 0x0)
C:/Gosrc/src/go/types/call.go:109 +0x339
go/types.(*Checker).exprInternal(0xc0000e06c0, 0xc0000d36c0, 0xf19ce0, 0xc0000d2400, 0x0, 0x0, 0x0)
C:/Gosrc/src/go/types/expr.go:1569 +0x1df0
go/types.(*Checker).rawExpr(0xc0000e06c0, 0xc0000d36c0, 0xf19ce0, 0xc0000d2400, 0x0, 0x0, 0x0)
C:/Gosrc/src/go/types/expr.go:1033 +0xc7
go/types.(*Checker).exprOrType(0xc0000e06c0, 0xc0000d36c0, 0xf19ce0, 0xc0000d2400)
C:/Gosrc/src/go/types/expr.go:1717 +0x5c
go/types.(*Checker).call(0xc0000e06c0, 0xc0000d36c0, 0xc0000d2440, 0xc00012e1e0)
C:/Gosrc/src/go/types/call.go:17 +0x78
go/types.(*Checker).exprInternal(0xc0000e06c0, 0xc0000d36c0, 0xf19ce0, 0xc0000d2440, 0x0, 0x0, 0x0)
C:/Gosrc/src/go/types/expr.go:1569 +0x1df0
go/types.(*Checker).rawExpr(0xc0000e06c0, 0xc0000d36c0, 0xf19ce0, 0xc0000d2440, 0x0, 0x0, 0x0)
C:/Gosrc/src/go/types/expr.go:1033 +0xc7
go/types.(*Checker).multiExpr(0xc0000e06c0, 0xc0000d36c0, 0xf19ce0, 0xc0000d2440)
C:/Gosrc/src/go/types/expr.go:1692 +0x58
go/types.(*Checker).exprList(0xc0000e06c0, 0xc000088610, 0x1, 0x1, 0x0, 0xdaa801, 0x2100000002030000, 0xc0000c79e8, 0x4)
C:/Gosrc/src/go/types/call.go:206 +0xb4
go/types.(*Checker).builtin(0xc0000e06c0, 0xc0000d3680, 0xc0000d2480, 0xc, 0xc0000d3600)
C:/Gosrc/src/go/types/builtins.go:47 +0x4c11
go/types.(*Checker).call(0xc0000e06c0, 0xc0000d3680, 0xc0000d2480, 0x0)
C:/Gosrc/src/go/types/call.go:56 +0xc9b
go/types.(*Checker).exprInternal(0xc0000e06c0, 0xc0000d3680, 0xf19ce0, 0xc0000d2480, 0x0, 0x0, 0x38)
C:/Gosrc/src/go/types/expr.go:1569 +0x1df0
go/types.(*Checker).rawExpr(0xc0000e06c0, 0xc0000d3680, 0xf19ce0, 0xc0000d2480, 0x0, 0x0, 0x0)
C:/Gosrc/src/go/types/expr.go:1033 +0xc7
go/types.(*Checker).stmt(0xc0000e06c0, 0x0, 0xf19f60, 0xc000088630)
C:/Gosrc/src/go/types/stmt.go:330 +0x3e78
go/types.(*Checker).stmtList(0xc0000e06c0, 0x0, 0xc000088640, 0x1, 0x1)
C:/Gosrc/src/go/types/stmt.go:125 +0xd6
go/types.(*Checker).funcBody(0xc0000e06c0, 0xc0000d4780, 0xc0000a2580, 0x4, 0xc0000d4840, 0xc0000b6e40, 0x0, 0x0)
C:/Gosrc/src/go/types/stmt.go:42 +0x268
go/types.(*Checker).funcDecl.func1()
C:/Gosrc/src/go/types/decl.go:790 +0x6e
go/types.(*Checker).processDelayed(0xc0000e06c0, 0x0)
C:/Gosrc/src/go/types/check.go:315 +0x45
go/types.(*Checker).checkFiles(0xc0000e06c0, 0xc0000cc0a0, 0x1, 0x1, 0x0, 0x0)
C:/Gosrc/src/go/types/check.go:283 +0x14d
go/types.(*Checker).Files(...)
C:/Gosrc/src/go/types/check.go:256
go/types.(*Config).Check(0xc0000d24c0, 0xc0000a2530, 0x4, 0xc0000d2240, 0xc0000cc0a0, 0x1, 0x1, 0xc0000d7310, 0x1, 0x0, ...)
C:/Gosrc/src/go/types/api.go:387 +0x188
go/go2go.rewriteFilesInPath(0xc0000d4240, 0x0, 0x0, 0xc0000b8140, 0x37, 0xc0000884a0, 0x1, 0x1, 0x0, 0x0, ...)
C:/Gosrc/src/go/go2go/go2go.go:93 +0x4dd
go/go2go.rewriteToPkgs(0xc0000d4240, 0x0, 0x0, 0xc0000b8140, 0x37, 0xc0000d2020, 0xc0000b8140, 0x37, 0xc0000a2080, 0x7)
C:/Gosrc/src/go/go2go/go2go.go:46 +0x16e
go/go2go.Rewrite(...)
C:/Gosrc/src/go/go2go/go2go.go:30
main.translate(0xc0000d4240, 0xc0000b8140, 0x37)
C:/Gosrc/src/cmd/go2go/translate.go:15 +0x4e
main.main()
C:/Gosrc/src/cmd/go2go/main.go:54 +0xb2f

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/jGrjr9a8M5W
  2. The generic type must contain at least one embedded constraint. Any embedded constraint will do.
  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.
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
You can’t perform that action at this time.