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: anonymous interface conversion not working #33602

Closed
randall77 opened this issue Aug 12, 2019 · 3 comments
Closed

cmd/compile: anonymous interface conversion not working #33602

randall77 opened this issue Aug 12, 2019 · 3 comments
Assignees
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Aug 12, 2019

With a directory structure like:

./go.mod
./c/c.go
./a/ssa/a.go
./b/ssa/b.go

go.mod:

module modpath

go 1.12

a.go:

package ssa

type T struct {
}

func (t *T) setNum(n int) {
}

var X interface{} = &T{}

func Run() {
	X.(interface {
		setNum(int)
	}).setNum(0)
}

b.go:

package ssa

type T struct {
}

func (t *T) setNum(n int) {
}

var X interface{} = &T{}

func Run() {
	X.(interface {
		setNum(int)
	}).setNum(0)
}

c.go:

package main

import (
	a "modpath/a/ssa"
	b "modpath/b/ssa"
)

func main() {
	a.Run()
	b.Run()
}

Then do

cd c
go build
./c

It fails with:

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

goroutine 1 [running]:
modpath/b/ssa.Run(...)
	/usr/local/google/home/khr/gowork/matloob/b/ssa/b.go:12
main.main()
	/usr/local/google/home/khr/gowork/matloob/c/c.go:10 +0x90

This bug requires that both interfaces in a and b be anonymous. Somehow they are being unified (by the linker?) and the test in package b is using the anonymous interface from package a, and failing because the unexported methods must match packages.

I suspect we qualify the unexported methods with only the package name, not the package path. The two anonymous interfaces here have the same linker name when using just the package names.

@matloob

@randall77 randall77 added this to the Go1.13 milestone Aug 12, 2019
@randall77 randall77 self-assigned this Aug 12, 2019
@cuonglm

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented Aug 12, 2019

Seems strange, in https://go-review.googlesource.com/c/go/+/170157, I did use package path qualified.

@cuonglm

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented Aug 12, 2019

@randall77 Seems it was fixed on tip, broken with go1.12.7.

@randall77

This comment has been minimized.

Copy link
Contributor Author

@randall77 randall77 commented Aug 12, 2019

Right, thanks.
Dup of issue 29612.

@randall77 randall77 closed this Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.