-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: suggest clearer error regarding when a non-pointer type cannot be used as type parameter #51515
Comments
I think your suggested error messages is too long. And it doesn't contain any information that is not in the existing error message. I don't mind changing the error message if we can find an improvement, but perhaps this is something to be addressed in blog posts rather than by changing the compiler. |
I think it comparably contains more straightforward suggestion on what is acceptable in this case
|
I hope that we can improve the error message. One problem for phrasing the message is that there's two ways to fix the underlying problem; either change I might phrase it as |
I agree there are two possible fixes. But speaking of likelihood, I would argue that "change
Comparing the original
to the discussed possibilities:
I think (1) is clear and avoids explicit suggestion, but only telling the factual information. |
Consider this example:
We may consider A and B both implements C. But the code produces error:
After parse the spec (precise but complex):
According to the spec (https://tip.golang.org/ref/spec#Implementing_an_interface) regarding the definition of a type `T` implements interface `I`:
Type set describes:
Method set describes:
The preceived understanding is:
Let
T
be a struct type. A pointer (*T
) to a defined typeT
. SinceT
contains a set of methods (I
) declared with receiver*T
orT
, henceI
is a type set, and*T
is an element of the type setI
.It is clear that only a pointer type is an element of a type set
C
(which is a method set with receiver*T
orT
), but this observation is much less intuitive to be aware in the beginning.Maybe a more clear error message might be:
Previously related #44201
The text was updated successfully, but these errors were encountered: