Navigation Menu

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
Milestone

Comments

@randall77
Copy link
Contributor

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
Copy link
Member

cuonglm commented Aug 12, 2019

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

@cuonglm
Copy link
Member

cuonglm commented Aug 12, 2019

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

@randall77
Copy link
Contributor Author

Right, thanks.
Dup of issue 29612.

@golang golang locked and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants