cmd/compile: _ methods should not be added to an interface's method set #42964
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
The spec does not permit blank (
_
) method names for interfaces:The compiler complains about such methods but still adds them to the method set, as evidenced by this program
The compiler complains that the
I
doesn't implementT
because of the missing_
method, hence the method must be present inT
. Interestingly, the modified programwhere
I
has a_
method, still results in the same error. This is due to the fact that_
methods cannot be found inI
as they are never declared.Furthermore, given the program
the compiler as before reports errors about the
_
methods being invalid but otherwise is quiet. Yet, the following versionreports the error
duplicate method _
because now the two_
methods have different signatures. While this is consistent with what we'd expect from any other method, it seems confusing.For contrast,
go/types
never adds the_
methods which results in fewer errors.See also
$GOROOT/test/interface/explicit.go
(at end) where there's an explicit test that nothing implements an interface with a_
method. Since it's not possible to declare such interfaces in the first place, it may be simpler to just ignore_
methods when encountering them in interface declarations, and then this last test would pass w/o error, and the above examples would only produce errors when the_
methods are declared.I'd like to see compelling evidence for keeping the existing behavior.
cc: @mdempsky
The text was updated successfully, but these errors were encountered: