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: interface conversion using OCONVNOP incorrectly #18595

Closed
rsc opened this issue Jan 10, 2017 · 1 comment
Closed

cmd/compile: interface conversion using OCONVNOP incorrectly #18595

rsc opened this issue Jan 10, 2017 · 1 comment

Comments

@rsc
Copy link
Contributor

rsc commented Jan 10, 2017

Keith noticed that this is wrong in the compiler:

// 2. src and dst have identical underlying types
// and either src or dst is not a named type or
// both are empty interface types.
// For assignable but different non-empty interface types,
// we want to recompute the itab.
if eqtype(src.Orig, dst.Orig) && (src.Sym == nil || dst.Sym == nil || src.IsEmptyInterface()) {
	return OCONVNOP
}

In the case where src and dst are interfaces of the same definition, but one is named and one is not, this code falls into OCONVNOP when it should (as the comment suggests) not do that and recompute the itab instead.

It makes this program print false instead of true:

package main

type I interface {
	M()
}

type T struct{}

func (*T) M() {}

func main() {
	t := new(T)
	var i1, i2 I
	var j interface {
		M()
	}
	i1 = t
	j = t
	i2 = j
	println(i1 == i2)
}

I think the if condition needs a && (!dst.IsInterface() || dst.IsEmptyInterface()) but I'd have to think harder about whether that's the only problem.

Leaving for Keith.

@rsc rsc added this to the Go1.9Early milestone Jan 10, 2017
@gopherbot
Copy link

CL https://golang.org/cl/35119 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 6, 2018
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