-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: method call on interface panics, but works on the contained struct #24547
Comments
That's an interesting test case. I get different results from different versions of Go. Go 1.1 through 1.6:
Go 1.7 through 1.9:
Go 1.10:
Current tip:
Go 1.10 is what the playground currently uses. It does seem that every version other than 1.10 agrees that the interface conversion does not succeed. Before 1.10 it is reported at run time. On tip it is reported at compile time. With gccgo, the program works as expected:
When I look at the type of the anonymous struct assigned to So it seems to me that gccgo is correct, and that gc is incorrect, in different ways for different versions. |
It looks like the problem is in expandmeth. We call expand1 to build up a list of all unique method names, and then we use dotpath to figure out which actual methods each of those names resolve to. However, when we record whether the promoted method is a "follows-ptr" method, we followed any pointers to discover the name in the first place. We should really be using whether dotpath had to follow any pointers. The compilation regression was caused by CL 100845 (91bbe53) because it changed interface satisfaction from using dotpath directly to using the cached results computed by expandmeth. |
The behaviors of By the example of the following program, package main
type mystruct struct {
field int
}
func (t mystruct) String() string {
return "foo"
}
type deep struct {
mystruct
}
func main() {
var d deep
_ = d.mystruct.String
_ = d.String
_ = d.mystruct.field
_ = d.field
} Is Is If the depth of |
@go101 OP's code is valid. It should behave as they described: s.String should refer to s.Buffer.String, as that has a lesser depth than s.deep.mystruct.String. |
Go spec is a little ambiguous here:
So |
Change https://golang.org/cl/102618 mentions this issue: |
Correct. |
It looks the tip only fix the fail-to-compile problem, but not the panic problem. |
sorry, my mistake. It is fixed on tip now. |
What version of Go are you using (
go version
)?go version go1.10 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/home/a/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/a"
GORACE=""
GOROOT="/home/a/go"
GOTMPDIR=""
GOTOOLDIR="/home/a/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build961933609=/tmp/go-build"
What did you do?
https://play.golang.org/p/TjVzZGtL8zz
What did you expect to see?
What did you see instead?
Are my expectations correct? I have reread the
Struct types
and theSelectors
paragraphs of the specs but I can't find an explanation for the panic, I hope I haven't overlooked something obvious.It seems related to the method collision (at different depths) and some specific combination of pointers and values.
The text was updated successfully, but these errors were encountered: