go: cmd/compile: panic on conversion to anonymous interface when 2 versions of library are built

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

$ go version
go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

yes it does

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/denis/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/denis/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nl/54f5x38s4m53mkzzj92zsj340000gn/T/go-build581161643=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run

git clone https://github.com/golangci/test4.git
go run main.go

and got

panic: interface conversion: *ssa.Call is not interface { ssa.setNum(int) }: missing method setNum

goroutine 1 [running]:
github.com/golangci/test2/ssa.Panics(0x105cde0, 0xc000064020, 0x2)
        /Users/denis/go/pkg/mod/github.com/golangci/test2@v0.0.0-20190108121323-b241e05eddb2/ssa/func.go:6 +0x82
main.main()
        /Users/denis/go/src/github.com/golangci/test4/main.go:14 +0xa0
exit status 2

What did you expect to see?

No panic with anonymous interface cast.

What did you see instead?

Panic.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 30 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Interesting. This has been broken since at least Go 1.1. It works with gccgo.

It does seem like something is very wrong. I’ve been able to minimize your test case to a single module with about half the amount of code, but still involving two packages with very similar types and the same package names.

$ git clone https://github.com/mvdan/go-issue-29612
$ cd go-issue-29612
$ go build
$ ./foo
Works succeeded
panic: interface conversion: *ssa.T is not interface { ssa.foo() }: missing method foo

goroutine 1 [running]:
test.tld/foo/p2/ssa.Panics(0x45ecc0, 0x4dce30)
        /home/mvdan/foo/p2/ssa/ssa.go:21 +0x52
main.main()
        /home/mvdan/foo/main.go:16 +0x88
$ # remove ssa1 from main.go; see the comment there
$ go build
$ ./foo
Works succeeded
Panics succeeded

This weird behavior happens on both 1.11.4 and go version devel +73fb3c38a6 Mon Jan 7 14:13:33 2019 +0000 linux/amd64. My best guess without any digging is that either the compiler or the runtime get confused by the very similar types in the very similar pakages, and there’s a conflict or misplacement somewhere.

The fact that removing the first ssa package from main.go makes the second ssa package work fine tells me that there’s no bug in either of the ssa packages.

/cc @randall77 @ianlancetaylor @dr2chase for some input