cmd/compile: interface conversion using OCONVNOP incorrectly #18595

Open
rsc opened this Issue Jan 10, 2017 · 1 comment

Projects

None yet

3 participants

@rsc
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
@randall77 randall77 was assigned by rsc Jan 10, 2017
@gopherbot

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment