cmd/compile: suggest clearer error regarding when a non-pointer type cannot be used as type parameter #51515
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
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: