github.com/neugram/ng@v0.0.0-20180309130942-d472ff93d872/eval/testdata/method5.ng (about) 1 methodik obj struct{ 2 V int 3 } { 4 func (*o) F() bool { return o.V == 3 } 5 func (o) G() bool { return o.V == 3 } 6 } 7 8 o := &obj{V: 3} 9 10 if !o.F() { 11 panic("pointer-reciever method failed") 12 } 13 if !(*o).G() { 14 panic("method call G failed") 15 } 16 if !o.G() { 17 panic("method promotion of G failed") 18 } 19 if !(*o).F() { 20 panic("pointer-reciever method promotion failed") 21 } 22 23 methodik intm int { 24 func (*i) IntP() int { return int(*i) } 25 func (i) Int() int { return int(i) } 26 } 27 i := intm(7) 28 v1 := i.IntP() 29 if v1 != 7 { 30 errorf("i.IntP()=%d, want 7", v1) 31 } 32 v2 := i.IntP() 33 if v2 != 7 { 34 errorf("i.Int()=%d, want 7", v2) 35 } 36 37 type Point struct { 38 X int 39 Y int 40 } 41 42 methodik Box struct { 43 T Point 44 U Point 45 } { 46 func (b) Volume() int { 47 return (b.U.X - b.T.X) * (b.U.Y - b.T.Y) 48 } 49 } 50 b := Box{ 51 T: Point{12, 3}, 52 U: Point{15, 9}, 53 } 54 if v := b.Volume(); v != 18 { 55 errorf("b.Volume()=%d, want 18", v) 56 } 57 58 print("OK")