-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: recommend fix when "method has pointer receiver" #44201
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
Comments
The
part explains clearly what the problem is, so the diagnostic is complete. You propose adding a sentence that also suggests a possible solution, which is a different thing. Not many errors in Go do that, because it makes every error message more verbose. This style of diagnostic is useful in complex languages, where it may not be obvious at all how to fix an issue, but I'm not sure this is the case. In my experience, after you've seen the "has pointer receiver" error once or twice, you quickly learn what it means (and how to fix it). |
What seems confusing to me is that the method So, why the parameter must be sent as a pointer with |
I think that In addition to this, if the argument is replaced with a pointer value, its type does not necessarily implement the interface. For example if the interface is
the error message is the same but If the corresponding pointer type ( If instead
|
I agreed that its confusing to say the least. A better message would be:
|
Go's diagnostic message when passing a non-pointer to a function taking an interface is confusing because it doesn't explain very well what the problem is.
Example (https://play.golang.org/p/MXm6RG5fYPy):
This produces the diagnostic:
... which is only half the story, and makes it difficult to see what's actually wrong. A better diagnostic would be:
The text was updated successfully, but these errors were encountered: