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: assigning to interface variable mentions only first missing method #13551

Closed
snakeru opened this issue Dec 9, 2015 · 2 comments
Closed

Comments

@snakeru
Copy link

snakeru commented Dec 9, 2015

Consider the following code (http://play.golang.org/p/0Sm13cKcq5):

type A interface {
    Read()
    Write()
}
var a A = 1

This fails to compile with the following message:
"cannot use 1 (type int) as type A in assignment: int does not implement A (missing Read method)"

The problem is that 'int' also misses the 'Write' method, but it is not disclosed until user works around by defining a custom type and implementing the missing method (only to realize that it was not the only one).

This behavior delivers surprises when using complex libraries and writing compartibility layers for them.

@mdempsky mdempsky changed the title Assigning to interface variable mentions only first missing method. cmd/compile: assigning to interface variable mentions only first missing method Dec 9, 2015
@mdempsky
Copy link
Member

mdempsky commented Dec 9, 2015

If there's only a couple missing methods, it seems reasonable to mention them all. But I don't think we want to list all 29 missing methods for:

var x reflect.Type = 1

Maybe something like this though?

cannot use 1 (type int) as type reflect.Type in assignment: int does not implement reflect.Type (missing Align, FieldAlign, Method, MethodByName, and 25 more methods)

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Dec 9, 2015
@odeke-em
Copy link
Member

odeke-em commented Oct 3, 2016

Also a duplicate of #8095.

This issue seems to be a hot topic (second duplicate of that issue)

Closing it in favor of #8095.

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

5 participants