On Fri, 28 Feb 2025 at 16:52, cpu...@gmail.com <cpui...@gmail.com> wrote:
> Thank you Axel for quoting the spec. > > On Thursday, February 27, 2025 at 10:55:58 PM UTC+1 Axel Wagner wrote: > > > For a value x of type T or *T where T is not a pointer or interface > type, x.f denotes the field or method *at the shallowest depth* in T > where there is such an f. If there is not exactly one f with shallowest > depth, the selector expression is illegal. > > The field `meter.EqualName` has a more shallow depth than > `meter.EqualName.EqualName`, thus `m.EqualName` denotes the field, not the > method. > Thus, the method is not promoted. Thus `meter` has no `EqualName` method, > as the only way it could get one is by promotion. > > > I can see why the EqualName method is not promoted. However, there is > still the EqualName field. Even if it's not useful (since zero value) I > would expect this fields to make meter implement the EqualName interface. > See https://play.golang.com/p/awtbP1X93Pg for an example that shows that > presence of an interface field is enough. > The two situations are not the same. Again, the salient question is "what is the shallowest depth b, that a.b could refer to?". That is what `a.b` means. And a method `b` is promoted to `a`, if `a.b` refers to a method. In this new example, `new(s).Foo` refers to the shallowest depth method or field `Foo`, which is `s.iface.Foo`, which is a method, so it is promoted. If `s` also had a field `Foo`, then `new(s).Foo` would refer to that field (as it is is at a shallower depth) and there is no method: https://play.golang.com/p/OFYNiB98qyJ That's your original example: `m.EqualName` refers to `meter.EqualName`, not `meter.EqualName.EqualName`. So it refers to a field, not a method, so no method is promoted. The spec is really clear on this regard. First you decide what the selector refers to. And that decides whether a method is promoted. Full stop. If you want to make an argument that `meter` should have a method `EqualName` you need to actually say where it is coming from. Given that you do not declare a method `func (meter) EqualName`, it could only get that method via promotion. But the definition of promotion of methods clearly says that no promotion is happening. > > Thanks, > Andi > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion visit > https://groups.google.com/d/msgid/golang-nuts/b4d16a1e-1c31-4cbb-8774-fc7b9d960d5fn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/b4d16a1e-1c31-4cbb-8774-fc7b9d960d5fn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEbys%3DkF1pQLjvMwjz4THtjET%3DQftM3cu67M%3DwhBaOHhQ%40mail.gmail.com.