Foo is declared as a new type, and no methods are declared on that that type. If you had declared:
type Foo = *Foo it would have been a different matter. On Sun, 24 Feb 2019, 10:30 pm , <roj...@gmail.com> wrote: > Why can't Go resolve methods declared on the pointer receiver of the > destination type? > > consider: > > type foo struct{ > bar int > } > > type Foo *foo > > func (f *foo) GetBar() int { > return f.bar > } > > func NewFoo(bar int) Foo { > return &foo{bar: bar} > } > > func main() { > f1 := &foo{bar: 123} > fmt.Printf("%d\n", f1.GetBar()) > f2 := NewFoo(456) > fmt.Printf("%d\n", f2.GetBar()) > } > > > (playground link: https://play.golang.org/p/v0f9pYaTJAa ) > > it fails to compile with "prog.go:25:23: f2.GetBar undefined (type Foo has > no field or method GetBar)" but it's not clear to me, why Foo doesn't get > pointer methods from *foo. > > -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.